Jump to content

echo "" is producing a <BR> effect


Freedom-n-Democrazy

Recommended Posts

I have written code so that when something from a MySQL field equals 0, then PHP will take no action, and if the field equals anything else, then 'echo "foo"'.

The problem I am having is that when PHP echo's nothing (echo ""), its still creating the effect of a HTML <BR>.

 

Screen shots:

 

1. When the MySQL table contains something else than 0 (echo "foo").

http://i51.tinypic.com/2n7oxo1.png

 

2. When the table contains 0 (echo "").

http://i53.tinypic.com/2h5jg4k.png

 

3. What it should look like if the table were to contain 0 (echo ""). Note that their is no <BR> effect.

http://i51.tinypic.com/2jdtaf.png

 

 

Code:

$query = "select sizes from products where id='$id'"; $result = mysql_query($query); $data = mysql_fetch_array($result); if ($data['sizes'] == 0) {echo "";} else {echo "Small - ".$data['sizes'];}

 

Is it possible to make it so if a MySQL field result equals 0, then PHP will not produce the HTML <BR> effect when it echo's nothing (echo "")?

Link to comment
Share on other sites

Why are you echoing anything at all? I'm not quite sure why it's producing a <br />-like effect, but the obvious and better, solution would be to not echo anything at all if no results turn up.

 

Better yet:

 

$query = "SELECT sizes FROM product WHERE id=" . intval($id);
if ($result = mysql_query($query))
{
    echo 'Small - ', $data['sizes'];
}

 

Code is much cleaner now.

Link to comment
Share on other sites

yeah dont bother echo anything if it fails saves all your problems.

 

also dont forget to wrap code in "code" tags when pasting on these forums. makes it easier to standout and is much better formatted, you will also get more sufficient help as some ignore code not wrapped in code tags.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.