Can you use PHP to show a default image if the image field in a database row is empty?
I'm creating a news page, but the client may not always upload an image with a news story. I know how to hide the area, but this leaves a big blank space. It would be much better if a default image were to appear.
There are a coule of solutions.
1) When they load the news item you could fill in the form with a default if they don't supply one so the default value is a link to the default image. this could be a simple as a default value in the table so would be really simple. Or you could code the default as the data goes into the table.
2) Have the HTML so that if there is no image the div or whatever does not display
3) As you loop through the data building the news page use an IF statement. If the image field is not empty then display it else dosplay default eg:
-
// data from a query in an associative array
-
foreach($laNews as $lcNewsItem)
-
{
-
if (empty($lcNewsItem['imageURL'])
-
{
-
$lcNewsItem['imageURL'] = "image/default.png";
-
}
-
echo.... // the line to display the image
-
}
-
I would opt for either option one or three. But, as always there are many solutiosn to one problem and you have to pick which is best for you. Also I'm sure other people will post other options.
Hopefully that's got you going.
Cheers
nathj