1. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Chicago, USA
    Rep Power
    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
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Rep Power

    while (($row = mysql_fetch_object($result))) {

    change that line into following..
    while (($row = mysql_fetch_array($result))) {

    SR -
    www.jobxyz.com-IT Career Portal

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    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.

IMN logo majestic logo threadwatch logo seochat tools logo