0

I have a line of PHP code for which I am getting an error.

while($row = mysql_fetch_array($result))

The line of code is the 60th line in my program,

Here's a link to the complete PHP code:

http://rancorous-rsps.com/SQL.java

I am getting the following error message:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/ranco690/public_html/highscores/index.php

Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • 1
    When `mysql_query()` gets an error it returns `false`. Echo `mysql_error()` to see the error message. – Barmar Apr 21 '13 at 03:19

2 Answers2

0

Your query $result = mysql_query("SELECT * FROM Ratio ORDER BY Kills DESC LIMIT 20"); must be incorrect. Check if you have tables Ration, column Kills. You need to test $result before proceeding.

For example:

if ( $result )
{
   while($row = mysql_fetch_array($result))
   {
      echo $row['playerName'];
      echo "<br />";
   }
   mysql_free_result($result);
}
else
   die( mysql_error()) ;

As you could notice, I added mysql_free_result($result); which you do not have.

Also ranco690_kill database may be improperly spelled. Try this:

mysql_select_db("ranco690_kill", $con) || die( "ranco690_kill does not exist." ) ;

Blessings, Greg.

Grzegorz
  • 3,207
  • 3
  • 20
  • 43
0

For a start you should be wrapping it in an 'if' make sure that results is a resource.

$result = mysql_query("SELECT * FROM Ratio ORDER BY Kills DESC LIMIT 20");

if ( $result ) {
    while($row = mysql_fetch_array($result))
    {
        echo $row['playerName'];
        echo "<br />";
    }
} else {
    // there is a problem ...
    echo mysql_error(); // display error so you can fix it
}
Michael Coxon
  • 5,311
  • 1
  • 24
  • 51