I am trying to write an if statement for image in my database. Example: if no image is relating to the recipeid do not post a blank image box leave blank as if there is nothing there..only show image for recipeid that has a picture.
This is my code that I have but I can not figure how to write the if code:
<?php $con = mysql_connect("localhost", "test", "test") or die('Could not connect to server'); mysql_select_db("recipe", $con) or die('Could not connect to database'); $recipeid = $_GET['id']; $query = "SELECT title,poster,shortdesc,ingredients,directions, calories, picture from recipes where recipeid = $recipeid"; $result = mysql_query($query) or die('Could not find recipe'); $row = mysql_fetch_array($result, MYSQL_ASSOC) or die('No records retrieved'); $title = $row['title']; $poster = $row['poster']; $shortdesc = $row['shortdesc']; $ingredients = $row['ingredients']; $directions = $row['directions']; $calories = $row['calories']; $picture = $row['thumbnail']; $ingredients = nl2br($ingredients); $directions = nl2br($directions); echo "<h2>$title</h2>\n"; echo "by $poster <br><br>\n"; echo $shortdesc . "<br><br>\n"; echo "<h3>Ingredients:</h3>\n"; echo $ingredients . "<br><br>\n"; echo "<h3>Directions:</h3>\n"; echo $directions . "\n"; echo "<h3>Calories:</h3>\n"; echo $calories . "<br><br>\n"; echo "<img src=\"showimage.php?id=$recipeid\" border=\"0\" ></a>\n"; echo "<br><br>\n"; ?>
Edited by mike_2000_17: Fixed formatting