Web Analytics Made Easy -
StatCounter echo is producing a <BR> effect - CodingForum

Announcement

Collapse
No announcement yet.

echo is producing a <BR> effect

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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").


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


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



    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; Sep 13, 2011, 10:00 AM.

  • #2
    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'];



    .

    Comment


    • #3
      Hey mlseim,

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

      Comment


      • #4
        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

        Comment


        • #5
          Nice try man, I tried something similar earlier... but yeah, didn't work either, it echo's "Small - 0"
          grrrrrr

          Comment


          • #6
            Try the modified code below - note the quotes (I suspect it's probably being pulled from MySQL as a string not an integer):

            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'];



            .
            "Tango says double quotes with a single ( ' ) quote in the middle"
            '$Name says single quotes with a double ( " ) quote in the middle'
            "Tango says double quotes ( \" ) must escape a double quote"
            '$Name single quotes ( \' ) must escape a single quote'

            Comment


            • #7
              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

              Comment


              • #8
                Sometimes I can't see the forest because there are too many trees in the way.



                .

                Comment


                • #9
                  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.

                  Comment


                  • #10
                    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; Sep 14, 2011, 05:43 AM.

                    Comment


                    • #11


                      LOL, what eva..

                      Comment


                      • #12
                        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.
                        "Tango says double quotes with a single ( ' ) quote in the middle"
                        '$Name says single quotes with a double ( " ) quote in the middle'
                        "Tango says double quotes ( \" ) must escape a double quote"
                        '$Name single quotes ( \' ) must escape a single quote'

                        Comment


                        • #13
                          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.

                          Comment


                          • #14
                            No it works fine. Take a look:


                            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?
                            "Tango says double quotes with a single ( ' ) quote in the middle"
                            '$Name says single quotes with a double ( " ) quote in the middle'
                            "Tango says double quotes ( \" ) must escape a double quote"
                            '$Name single quotes ( \' ) must escape a single quote'

                            Comment

                            Working...
                            X
                            😀
                            🥰
                            🤢
                            😎
                            😡
                            👍
                            👎