Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts

    echo is producing a <BR> effect

    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:
    PHP 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 "")?
    Last edited by Democrazy; 09-13-2011 at 03:00 PM.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,387
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    How about this ...

    PHP Code:
    $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'];



    .

  • #3
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Hey mlseim,

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

  • #4
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    What about this:
    PHP Code:
    $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'];

    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #5
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Nice try man, I tried something similar earlier... but yeah, didn't work either, it echo's "Small - 0"
    grrrrrr

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Try the modified code below - note the quotes (I suspect it's probably being pulled from MySQL as a string not an integer):

    Quote Originally Posted by mlseim View Post

    PHP Code:
    $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'];



    .
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #7
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by tangoforce View Post
    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.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #8
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,387
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    Sometimes I can't see the forest because there are too many trees in the way.



    .

  • #9
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Hey guys, sorry for my slow update.. I've had job interviews all day (I'm unemployed )

    tangoforce, I tried your code as suggested:
    PHP Code:
    $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.

  • #10
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    I solved it myself with the classic "goto" and official documentation for reference how its used in PHP:

    PHP Code:
    if ($data['sizes'] == 0) {goto sizem;} else {echo "Small - ".$data['sizes'];}
    echo 
    "<BR>";
    sizem
    So proud!
    Last edited by Democrazy; 09-14-2011 at 10:43 AM.

  • #11
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by Democrazy View Post

    tangoforce, I tried your code as suggested:
    PHP Code:
    $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.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #13
    Banned
    Join Date
    Sep 2011
    Posts
    140
    Thanks
    17
    Thanked 0 Times in 0 Posts
    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.

  • #14
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    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?
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •