I run a query, lets say…
SELECT * FROM contacts WHERE category = "customers"
I get an empty result set because there are no contacts that are customers
How would I display a custom message with PHP? For example, something that would let me say “Sorry, there are no results”.
I tried
if(empty($result))
{
echo 'Sorry, there are no results.';
}
but doesn’t work
$data = @mysql_fetch_assoc($result);
if(empty($data)… etc
Or you could use
$result = @mysql_query($sql) or die("ERROR - Unable to select the database-".mysql_error());
$count = @mysql_num_rows($result);
if($count > 0)
{
//fetch array or whatever
}
else
{
//Display "no results found" message
}
Thanks! I came up with this:
$result = mysql_query($query);
if(!$result){$error.= 'Query failed: '.mysql_error();}
// IF THERE ARE NO RESULTS DISPLAY MESSAGE
$fetch_row = mysql_fetch_row($result);
$numrows = $fetch_row[0];
if($numrows==0)
{
echo 'There are no articles in this category yeeeet, check back soon.';
}
soooo … you made an array of an array? was there a reason for that?
[QUOTE=simplistik;2337328]soooo … you made an array of an array? was there a reason for that?[/QUOTE]
hey simplistik! long time no contact.
what do you mean an array of an array?
I made a query like…
SELECT * FROM articles WHERE category1 = "Apache"
If there were no rows returned from the query I wanted to display a message like…
" There are no articles from this category"