note 88650 deleted from function.mysql-num-rows by thiago
| From: | thiago@php.net | Date: | Mon, 02 Feb 2009 12:29:26 +0000 |
| Subject: | note 88650 deleted from function.mysql-num-rows by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150097@lists.php.net to get a copy of this message | ||
Note Submitter: testing_guru at indiatimes dot com
----
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...