Jump to content

Archived

This topic is now archived and is closed to further replies.

webref.eu

[resolved] Syntax for If No Results from Query

Recommended Posts

Hi All

If I have an SQL query which yields no results, what is the syntax for testing there are no results in an If statement? 

FYI my code uses the following: 

//assign query results to a result variable
$result = mysql_query($query);

if(!$result) die("Query Failed.");

//associative array allows you to use field names to get results
while($row = mysql_fetch_array($result, MYSQL_ASSOC)

Many thanks

WebRef.eu

Share this post


Link to post
Share on other sites
mysql_num_rows() ... if it's a valid query

Share this post


Link to post
Share on other sites
For select queries use mysql_num_rows($result) like andy said. For update, delete or insert queries use mysql_affected_rows().

Share this post


Link to post
Share on other sites

×

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.