October 13th, 2000, 06:10 PM
-
I'm going through the book Pro. PHP Programming where there is an addressbook script designed to show the use of MySQL. I am getting the following error when trying to search the address book:
Warning: 0 is not a MySQL result index in /path/to/the/search.php/script on line 60.
This is referring the the following line of code (line 60):
while (($row = mysql_fetch_object($result))) {
What does the error mean...
------------------
Welcome everybody, my name is Moe...otherwise known to the ladies as "hey you in the bushes". - Moe Sizlak
October 13th, 2000, 06:44 PM
-
October 13th, 2000, 09:16 PM
-
In my experience, this is a sign that your SQL query returned nothing...
Then you jump into your while statement.
To avoid little error messages like this, you can add the "@" sign to the beginning of the mysql statement..
while ($row = @mysql_fetch_object($result)) {
}
Note that when you do that, those errors will go away, and so will output, unless you check for it...
One way to do it add a small "if" statement, before your while statement....
something like this:
$num = mysql_num_rows($result);
if ($num > 0) {
now execute my while...
}
Mind you there are other ways to do it..
But the answer to your question is that PHP attempted to something with a mysql result set, the result set was empty, and therefor
0.. so you get the error.
If you querry should be returning nothing, ie. your db is empty, or something, then you'll probably want to cover for this in the future, the "@" sign will help.
If you think the query should return something, double check the query, make sure it's correct.. and then naturally correct the syntax of your while statement..
------------------
SnR Graphics,
Low Cost Hosting and Web Development.