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 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with if else syntax

    There is something wrong with my syntax in my if else statement (actually it's in the echo part of the 5th line and has to do with how I'm pulling the image from the database).

    This works:
    <?php
    if (($row_news['thumbnail'])==NULL)
    echo "a";
    else
    echo "<img src='images/a.jpg' alt='title' border='1' align='left' class='paddedimage' />";
    ?>
    This does not:
    <?php
    if (($row_news['thumbnail'])==NULL)
    echo "a";
    else
    echo "<img src='$row_news['thumbnail']' alt='title' border='1' align='left' class='paddedimage' />";
    ?>
    What am I doing wrong?

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    472
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I think you need brackets, like this:

    PHP Code:
    <?php
    if (($row_news['thumbnail'])==NULL) {
    echo 
    "a";
    }
    else {
    echo 
    "<img src='$row_news['thumbnail']' alt='title' border='1' align='left' class='paddedimage' />";
    }
    ?>
    If you're reading this, it may already be too late!

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I tried it, but that didn't work either. This is the error I get if it helps:

    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /export/httpd/data/academic/cit/test/farrah/news.php on line 66

    And the line that it breaks on is the one with the image that is being pulled from the database.

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Location
    Texas
    Posts
    472
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hmm, try this:

    PHP Code:
    <?php
    if (($row_news['thumbnail'])==NULL) {
    echo 
    "a";
    }
    else {
    echo 
    "<img src='".$row_news['thumbnail']."' alt='title' border='1' align='left' class='paddedimage' />";
    }
    ?>
    If you're reading this, it may already be too late!

  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That did it... thank you!!!


  •  

    Posting Permissions

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