Jump to content

PHP if null, end help


Call-911

Recommended Posts

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

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);
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.