Click to See Complete Forum and Search --> : I am not sure if this is a MySql or php problem.


gogelpot
09-13-2006, 04:09 AM
Hi

I am not sure if this is a MySql or php problem.

How do I check if a mysql table is empty?

I have used this code:


$Exist = "SELECT * FROM log WHERE CName='$CName' AND League='$Liga AND Day='$Days'";
$result = mysql_query($Exist);
$num=mysql_numrows($result);


to search the table for the content but if the table is empty with no data rows in it I get the following error.

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\Xitami\webpages\WPCricket\Data Admin\Addresult.php on line 266

Line 266 is $num=mysql_numrows($result);

How do I prevent this error?

Pleas help.

pcthug
09-13-2006, 04:50 AM
The mysql_numrows function is deprecated, use the mysql_num_rows function instead. Also make use of the mysql_errno and mysql_error functions.

$Exist = "SELECT * FROM log WHERE CName='$CName' AND League='$Liga AND Day='$Days'";
$result = mysql_query($Exist) or die(mysql_errno() . ": " . mysql_error() . "\n");
$num = @mysql_num_rows($result);

bokeh
09-13-2006, 05:09 AM
The mysql_numrows function is deprecated, use the mysql_num_rows function instead. Also make use of the mysql_errno and mysql_error functions.

$Exist = "SELECT * FROM log WHERE CName='$CName' AND League='$Liga AND Day='$Days'";
$result = mysql_query($Exist);
$num = @mysql_num_rows($result) or die(mysql_errno() . ": " . mysql_error() . "\n");
You should have the die statement on the query line.$result = mysql_query($query) or die('etc');

pcthug
09-13-2006, 05:22 AM
Careless mistake...