Call-911 Posted January 12, 2011 Share Posted January 12, 2011 Hello All, I tried searching here and google, but couldn't figure it out on my own... still Bellow is my code, I need some help figuring out how to tell PHP that "If picture is NULL, don't try to display it." Basically I have a dynamic news system set up. Some stories have pictures, some do not. I need PHP to not display the code for showing the picture if the picture value = NULL. Any help would be appreciated! <?php include ("../../includes/connections/newsconnection.php"); $id=$_GET['id']; //declare the SQL statement that will query the database $query = " SELECT * FROM news WHERE id='$id' "; //execute the SQL query and return records $result = mssql_query($query); //display the results //id, school, date, link, title, story, picture while($row = mssql_fetch_array($result)) { echo "<span class='bodyb'>"; echo $row["title"]; echo "</span>"; echo "<br /><i>"; echo date('l, F j, Y', strtotime($row['date'])); echo "</i>"; echo "<br /><br />"; //heres where I need to stop if picture is null echo "<img src='../../images/news/"; echo $row["picture"]; echo "' align='left' class='imgspacer-left'>"; echo fixQuotes($row["story"]); } //close the connection mssql_close($dbhandle); ?> Link to comment https://forums.phpfreaks.com/topic/224185-php-if-null-end-help/ Share on other sites More sharing options...
dragon_sa Posted January 12, 2011 Share Posted January 12, 2011 if ($row["picture"]!='NULL') { echo $row["picture"]; } Link to comment https://forums.phpfreaks.com/topic/224185-php-if-null-end-help/#findComment-1158368 Share on other sites More sharing options...
Call-911 Posted January 12, 2011 Author Share Posted January 12, 2011 Thanks for the help, but I think I did it wrong. It stops loading the rest of the page after the code. I think I put it in wrong.... <?php include ("../../includes/connections/newsconnection.php"); $id=$_GET['id']; //declare the SQL statement that will query the database $query = " SELECT * FROM news WHERE id='$id' "; //execute the SQL query and return records $result = mssql_query($query); //display the results //id, school, date, link, title, story, picture while($row = mssql_fetch_array($result)) { echo "<span class='bodyb'>"; echo $row["title"]; echo "</span>"; echo "<br /><i>"; echo date('l, F j, Y', strtotime($row['date'])); echo "</i>"; echo "<br /><br />"; echo fixQuotes($row["story"]); if ($row("picture")!='NULL') echo "<img src='../../images/news/"; if ($row("picture")!='NULL') echo $row["picture"]; if ($row("picture")!='NULL') echo "' align='left' class='imgspacer-left'>"; } //close the connection mssql_close($dbhandle); ?> Link to comment https://forums.phpfreaks.com/topic/224185-php-if-null-end-help/#findComment-1158621 Share on other sites More sharing options...
dragon_sa Posted January 12, 2011 Share Posted January 12, 2011 if ($row["picture"]!='NULL') { echo "<img src='../../images/news/".$row["picture"]."' align='left' class='imgspacer-left'>"; } you had the wrong brackets around picture in the if statement Link to comment https://forums.phpfreaks.com/topic/224185-php-if-null-end-help/#findComment-1158648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.