Jump to content

Count Rows


pranshu82202

Recommended Posts

:confused: Can any one tell me whats the best ( actually error free ) which i can use to count the number of rows finally resulting after select command.

 

I use this ...

 

$sql = mysql_query("select * from usname where name1='$name1' and name2='$name2' and amm='$amm'"); 
$num=mysql_num_rows($sql); 
echo $num;

 

But it always gives the same error.... and the error is..........

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\money\insert.php on line 20

 

where line 20 is...

 

$num=mysql_num_rows($sql); 

 

- Pranshu Agrawal

[email protected]

Link to comment
https://forums.phpfreaks.com/topic/252660-count-rows/
Share on other sites

That error, for the posted code, means that the query failed due to an error of some kind (connection problem, sql syntax error, wrong table/column names, un-escaped string data being put into the query statement.)

 

You would need to troubleshoot why the query is failing. You can echo mysql_error(); to get php/mysql to tell you why the query is failing.

Link to comment
https://forums.phpfreaks.com/topic/252660-count-rows/#findComment-1295257
Share on other sites

Thanks PFMaBiSmAd, I got the issue ..... actually the table name i am using is not correct............

 

 

Thanks for the help

The logic isn't correct either.  You probably want where name = 'name1' OR name = 'name2'.  A single field can never be the same as two different things.
Link to comment
https://forums.phpfreaks.com/topic/252660-count-rows/#findComment-1295263
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.