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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.