Jump to content


Photo

Number of results problem


  • Please log in to reply
2 replies to this topic

#1 Cronje

Cronje
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 June 2006 - 08:11 AM

I'm trying to determine the number of results from a SELECT, but am having trouble. My code:
$query = mysql_query("SELECT * FROM tablename WHERE name='xxx'");
$num = mysql_num_rows($query);

It works fine when 'xxx' is in the table, but when it finds none, 'echo $num;' doesn't display anything.

Help please!

-Cronje

#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 01 June 2006 - 08:30 AM

How about this ?

$query = mysql_query("SELECT * FROM tablename WHERE name='xxx'");
$num = (int)mysql_num_rows($query);
Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 Cronje

Cronje
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 June 2006 - 08:36 AM

That worked perfectly. Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users