-3

I have this error : Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/xgamming/public_html/list.php on line 149

here is my code from list.php file at line no. 149

    while($row = mysql_fetch_array($result))    {
        echo "<tr>

        <td>{$count}</td>
        <td><font \color=\"blue\">{$row['ip']}:{$row['port']}</b></font></td>
        <td> {$row['drops']}</td>
        <td>{$row['last']}</td>
        <td><a href=\"http://www.gametracker.com/server_info/{$row['ip']}:{$row['port']}/\" target=\"_blank\"><img src=\"http://cache.www.gametracker.com/server_info/{$row['ip']}:{$row['port']}/b_350_20_FFFFFF_FFFFFF_000000_000000.png\" border=\"0\" width=\"300\" height=\"20\" alt=\"\"/></a></td>

        </tr>";

       $count++;

     }

     echo "</table></font>";
 ?>

 </div>

I have a MySQL database, empty, no table. How I can solve it?

swiftBoy
  • 35,607
  • 26
  • 136
  • 135

1 Answers1

2

If your query fails, then mysql_query returns a boolean, instead of a result set pointer.

When you directly pass the result set to any mysql_fetch_* operation, you will get this error.

You need to elegantly handle query failures yourself whenever one happens.

$result = mysql_query($someQuery);
if(!$result) {
    echo "An error occurred!";
    //Any more handling.
}
else {
    //Normal query processing.
}

Alternatively, you can use Exceptions.

As a side note, please don't use MySQL as it is deprecated now. Use MySQLi or PDO.

Achrome
  • 7,773
  • 14
  • 36
  • 45