...

View Full Version : echo is producing a <BR> effect



Democrazy
09-13-2011, 06:28 AM
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, 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 "")?

mlseim
09-13-2011, 12:26 PM
How about this ...



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





.

Democrazy
09-13-2011, 02:46 PM
Hey mlseim,

I tried the code you suggested, but it didn't work. :(

Rowsdower!
09-13-2011, 02:49 PM
What about this:

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

Democrazy
09-13-2011, 03:15 PM
Nice try man, I tried something similar earlier... but yeah, didn't work either, it echo's "Small - 0"
grrrrrr

tangoforce
09-13-2011, 03:22 PM
Try the modified code below - note the quotes (I suspect it's probably being pulled from MySQL as a string not an integer):






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





.

Rowsdower!
09-13-2011, 03:30 PM
Try the modified code below - note the quotes (I suspect it's probably being pulled from MySQL as a string not an integer):

Ohhh, good call on that one. :thumbsup:

mlseim
09-13-2011, 03:33 PM
Sometimes I can't see the forest because there are too many trees in the way.



.

Democrazy
09-14-2011, 10:16 AM
Hey guys, sorry for my slow update.. I've had job interviews all day (I'm unemployed :()

tangoforce, I tried your code as suggested:

$query = "select sizes from products where id='$id'";
$result = mysql_query($query);
$data = mysql_fetch_array($result);
if (isset($_POST['submit'])) {echo "";} else {echo "Small - ".$data['sizes'];}
... but it didn't work. Its showing "Small - 0".

Thanks for trying anyway bro.

Democrazy
09-14-2011, 10:28 AM
I solved it myself with the classic "goto" and official documentation for reference how its used in PHP:



if ($data['sizes'] == 0) {goto sizem;} else {echo "Small - ".$data['sizes'];}
echo "<BR>";
sizem:


So proud! :D

Democrazy
09-14-2011, 10:34 AM
http://www.kwista.com/wp-content/uploads/2010/04/goto.jpg

LOL, what eva..

tangoforce
09-14-2011, 11:00 AM
tangoforce, I tried your code as suggested:

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


No you didn't, you've tried something totally different using the submit button (which as my signature says, you should never use).

Go back, cope the modified code I quoted and get back to us again. There is no reason for it not to work.

Democrazy
09-14-2011, 11:28 AM
LOL I was actually looking at your signature thinking that was the reply.

Might want to shorten it dude. :)

I tried the code you pasted also, but it didn't work either.

tangoforce
09-14-2011, 12:58 PM
No it works fine. Take a look:
http://codepad.org/zRzWMzWu

Use that and strip out my test lines at the top.

Something else must be wrong with your code.

As for my signature, yes its large and its to help people like you so I won't be reducing it any time soon. Also if you thought that was part of my reply then why on earth did you go against it and use the submit button? :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum