Jump to content

mysql_num_rows() failed hopelessly


hvle

Recommended Posts

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.
Link to comment
Share on other sites

You probably should do something to check if the result set for your query is correct (if there is no sql-error, that is):
[code]
$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;
}[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.