Hello...
When querying a database, how can you tell whether or not the query actually returns any information? Possibly to output a notice that no information was returned.
thanks,
sod
| SitePoint Sponsor |
Hello...
When querying a database, how can you tell whether or not the query actually returns any information? Possibly to output a notice that no information was returned.
thanks,
sod
$numResults = mysql_num_rows($result);
if($numResults == 0){
blah blah
}else{
blah blah
}
Chris Beasley - I publish content and ecommerce sites.
Featured Article: Free Comprehensive SEO Guide
My Guide to Building a Successful Website
My Blog|My Webmaster Forums
Thanks a lot...that's exactly what I needed. I had no idea that function existed..guess I should go on php.net more often..

I usually use this instead...is it a problem?
if ($result)
{
blah blah
}
else
blah
That works for me, although the former example is possibly more correct.
d-net your code will tell you if the query was successfully executed. It can be successfully executed and still return 0 results. Basically what you're doing is used for error handling.
The code I posted is what you'd use to see if the query returned any results at all, assuming it was successfully executed.
Chris Beasley - I publish content and ecommerce sites.
Featured Article: Free Comprehensive SEO Guide
My Guide to Building a Successful Website
My Blog|My Webmaster Forums
Bookmarks