Freedom-n-Democrazy Posted September 13, 2011 Share Posted September 13, 2011 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 "")? Quote Link to comment https://forums.phpfreaks.com/topic/247019-echo-is-producing-a-effect/ Share on other sites More sharing options...
Pandemikk Posted September 13, 2011 Share Posted September 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247019-echo-is-producing-a-effect/#findComment-1268603 Share on other sites More sharing options...
web_craftsman Posted September 13, 2011 Share Posted September 13, 2011 PHP will not produce the HTML <BR> effect PHP does not produce any html if it is not said. So give us more your code. echo ''; this code have not got any sence. It does nothing. Quote Link to comment https://forums.phpfreaks.com/topic/247019-echo-is-producing-a-effect/#findComment-1268609 Share on other sites More sharing options...
jacko_162 Posted September 13, 2011 Share Posted September 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247019-echo-is-producing-a-effect/#findComment-1268651 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.