...

View Full Version : help with if else syntax



farrah
06-28-2007, 02:24 PM
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?

Digger3000
06-28-2007, 02:31 PM
I think you need brackets, like this:


<?php
if (($row_news['thumbnail'])==NULL) {
echo "a";
}
else {
echo "<img src='$row_news['thumbnail']' alt='title' border='1' align='left' class='paddedimage' />";
}
?>

farrah
06-28-2007, 03:01 PM
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.

Digger3000
06-28-2007, 03:05 PM
Hmm, try this:


<?php
if (($row_news['thumbnail'])==NULL) {
echo "a";
}
else {
echo "<img src='".$row_news['thumbnail']."' alt='title' border='1' align='left' class='paddedimage' />";
}
?>

farrah
06-28-2007, 03:28 PM
That did it... thank you!!! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum