Jump to content

IF nothing matches the variable in the field, display nothing?


spikypunker

Recommended Posts

How do i achieve this? I've been planning out a new bit for a page on my site, and i know that currently, if any of my requests come back blank ie

 

"SELECT from table WHERE venue='o2 arena' "

 

And there IS NO 'o2 arena' in the database, instead of displaying nought, it displays some error messages.

 

In the new bit for my site, at first most of the time it will coming back empty!

 

So how do i do an, IF EMPTY { } else {}

 

?? :os

You can count the number of result after the query like that :

 

$sql = "SELECT from table WHERE venue='o2 arena'";
$result = mysql_query($sql);
if (!$result) {
    die('Invalid query: '.$sql.' -- '.mysql_error());
}

if (mysql_num_rows($result) > 0)
{
/* display your data */
} else {
echo "No results.";
}

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.