0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

This is my code. It was working earlier, now isn't.

            <?php
        include("db.php");
        ob_start();


        $result=mysql_query("SELECT * FROM navigation order by pos asc");

        while($nav = mysql_fetch_array($result))
        {
            $id = $nav['navid'];    
            echo '<a href="' . $nav['link'] . '" target="'. $nav['target'] .'">';
            echo "<span class='link'>". $nav['text']. "</span></a>";
        }
        mysql_close($conn);
        ob_flush();
        ?>

Can anyone see the problem?

It's giving me this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in.

Thanks.

Community
  • 1
  • 1
Eddie
  • 351
  • 3
  • 17

1 Answers1

3

If $result is a boolean, it is false, which means that the query failed here:

$result=mysql_query("SELECT * FROM navigation order by pos asc");

See the documentation:

Return Values

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

You can use mysql_error to know what the error is.

You can also avoid the warning with:

$result=mysql_query("SELECT * FROM navigation order by pos asc");

if ($result) {
    while($nav = mysql_fetch_array($result))
    {
    ...
    }
}

Also note that the mysql extension for PHP is discouraged and might be removed in future versions

Matthieu Napoli
  • 45,472
  • 43
  • 162
  • 249