narjis Posted May 21, 2011 Share Posted May 21, 2011 I am unable to execute mysql_num_rows properly in this program. <?php $link=mysql_connect("localhost","root",""); $db = mysql_select_db("myDB",$link); $result = mysql_query("SELECT * FROM jobs WHERE jobType=abc"); $num = mysql_num_rows($result); echo "Found $num records"; ?> error is mysql_num_rows() expects parameter 1 to be resource Quote Link to comment https://forums.phpfreaks.com/topic/237028-somebody-check-pls/ Share on other sites More sharing options...
play_ Posted May 21, 2011 Share Posted May 21, 2011 The query failed. probably selecting from a wrong table or selecting wrong column.... i think. You should look into PHP's PDO class http://php.net/manual/en/book.pdo.php Quote Link to comment https://forums.phpfreaks.com/topic/237028-somebody-check-pls/#findComment-1218323 Share on other sites More sharing options...
trq Posted May 21, 2011 Share Posted May 21, 2011 You should always check your queries for success before using any data they might return. if ($result = mysql_query("SELECT * FROM jobs WHERE jobType = 'abc'")) { $num = mysql_num_rows($result); echo "Found $num records"; } Note I also fixed your query which was missing quotes around the string 'abc'. Quote Link to comment https://forums.phpfreaks.com/topic/237028-somebody-check-pls/#findComment-1218344 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.