Jump to content


Photo

[resolved] Syntax for If No Results from Query


  • Please log in to reply
3 replies to this topic

#1 webref.eu

webref.eu
  • Members
  • PipPipPip
  • Advanced Member
  • 213 posts

Posted 23 August 2006 - 08:15 PM

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
WebRef.eu - Internet Marketing Resources

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 August 2006 - 08:16 PM

mysql_num_rows() ... if it's a valid query
Legend has it that reading the manual never killed anyone.
My site

#3 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 23 August 2006 - 08:24 PM

For select queries use mysql_num_rows($result) like andy said. For update, delete or insert queries use mysql_affected_rows().

#4 webref.eu

webref.eu
  • Members
  • PipPipPip
  • Advanced Member
  • 213 posts

Posted 23 August 2006 - 08:48 PM

Thanks guys, that's great.

Rgds

WebRef.eu
WebRef.eu - Internet Marketing Resources




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users