note 88650 added to function.mysql-num-rows
| From: | testing_guru at indiatimes dot com | Date: | Mon, 02 Feb 2009 11:55:09 +0000 |
| Subject: | note 88650 added to function.mysql-num-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150094@lists.php.net to get a copy of this message | ||
When I first tried the following code while designing my site http://lifeisdelightful.com, I got an error message
"mysql_num_rows(): supplied argument is not a valid MySQL result resource". I was
desperately searching how to resolve this error, but was unsuccessful! Later I found a silly mistake
in my code and when I corrected it, the same code worked perfectly fine!!
Old code:
======
$records = mysql_query("SELECT * FROM table_name");
$count = mysql_num_rows($records); //***ERROR***
echo "Count: $count";
...
...
$link = mysql_connect('localhost', 'user_name', 'password');
$selected_db = mysql_select_db("database_name", $link);
...
...
======
Did anyone point out the error? It actually arises because the database connection is created later
in the code but I am trying to execute the query without a valid connection! And thats why this
weird error "mysql_num_rows(): supplied argument is not a valid MySQL result resource" is
generated...
New code:
======
$link = mysql_connect('localhost', 'user_name', 'password');
$selected_db = mysql_select_db("database_name", $link);
...
...
$records = mysql_query("SELECT * FROM table_name");
$count = mysql_num_rows($records); //***ERROR***
echo "Count: $count";
...
...
======
Hope this helps...
----
Server IP: 69.147.83.197
Probable Submitter: 59.160.13.22
----
Manual Page -- http://www.php.net/manual/en/function.mysql-num-rows.php
Edit -- https://master.php.net/note/edit/88650
Del: integrated -- https://master.php.net/note/delete/88650/integrated
Del: useless -- https://master.php.net/note/delete/88650/useless
Del: bad code -- https://master.php.net/note/delete/88650/bad+code
Del: spam -- https://master.php.net/note/delete/88650/spam
Del: non-english -- https://master.php.net/note/delete/88650/non-english
Del: in docs -- https://master.php.net/note/delete/88650/in+docs
Del: other reasons-- https://master.php.net/note/delete/88650
Reject -- https://master.php.net/note/reject/88650
Search -- https://master.php.net/manage/user-notes.php