Jump to content


Photo

mysql_num_rows() failed hopelessly


  • Please log in to reply
3 replies to this topic

#1 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 28 April 2006 - 07:28 AM

mysql_num_rows() has strangely failed in Window platform.

well, I have this code

Line 1: $sql = "select ......";
Line 2: $rs = mysql_query($sql);
Line 3: $rowcount = mysql_num_rows($rs);
Line 4: somecode here
very basic and it works fine in Linux system my host server
however, in my local system (Windows) it failed every time $rs is empty.

What happened is if $rs returned a non-empty set, $rowcount will contain number of rows in that $rs and proceed to Line 4.
When a select statement that returned an empty set, the script just halt (simply stop and exit) right at
Line 3;

I have read the PHP documentation on mysql_num_rows() and it does not state any platform incompatiblity regarding this function. I hope somebody with more experiences would explain why it behaved this way.

Thanks a million.

Life's too short for arguing.

#2 predator12341

predator12341
  • Members
  • PipPipPip
  • Advanced Member
  • 87 posts
  • LocationCheshunt, Hertfordshire, England

Posted 28 April 2006 - 08:28 AM

hi can we look at the sql statement you are using please

[a href="http://www.sloganizer.net/en/" target="_blank"][/a]

#3 koencalliauw

koencalliauw
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 28 April 2006 - 09:38 AM

You probably should do something to check if the result set for your query is correct (if there is no sql-error, that is):
$sql="select * from employees";
$res=@mysql_query($sql);
if($res!=FALSE)
{
    echo mysql_num_rows($res);
}
else
{
    echo "There was an error in your SQL query: " . mysql_error() . "\n<br />The given SQL query was: " . $sql;
}


#4 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 28 April 2006 - 12:54 PM

Thanks for all replies,

After a lot of testing, i found the error on another module. The problem is not mysql_num_rows
Life's too short for arguing.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users