0

After fixing my main MySQL error, I now that a problem with the PHP on the website that includes the MySQL table I created. I am receiving the text:

Website link directly to error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/content/26/10406626/html/highscore/index.php on line 258

This is where I have $result in the file:

if ($skill == "Attack" || $skill == "Defence" || $skill == "Strength" || $skill == "Hitpoints" || $skill == "Range" || $skill == "Prayer" || $skill == "Magic" || $skill == "Cooking" || $skill == "Woodcutting" || $skill == "Fletching" || $skill == "Fishing" || $skill == "Firemaking" || $skill == "Crafting" || $skill == "Smithing" || $skill == "Mining" || $skill == "Herblore" || $skill == "Agility" || $skill == "Thieving" || $skill == "Slayer" || $skill == "Farming" || $skill == "Runecraft" || $skill == "Hunter" || $skill == "Construction" || $skill == "Summoning" || $skill == "Dungeoneering")  {
    mysql_select_db("scores", $con);
    $result = mysql_query("SELECT * FROM skills WHERE ". $PLAYERS_TO_NOT_SHOW . " ORDER BY " . $skill . "lvl DESC, " . $skill . "xp DESC");
    }

else {
    $skill = "";
    mysql_select_db("scores", $con);
    $result = mysql_query("SELECT * FROM skillsoverall WHERE ". $PLAYERS_TO_NOT_SHOW . " ORDER BY lvl DESC, xp DESC");
    }

This is line 254 to 278: Obviously, line 258 is *while($row = mysql_fetch_array($result))*

<?php

$rank = 1;

while($row = mysql_fetch_array($result))
    {
    echo "<a name=\"" . $rank . "\"></a>";
    echo "<a class=\"row\">";
    echo "<span class=\"columnRank\">";
    echo "<span>" . $rank . "</span>";
    echo "</span>";
    echo "<span class=\"columnName\">";
    echo "<span>" . $row['playerName'] . "</span>";
    echo "</span>";
    echo "<span class=\"columnLevel\">";
    echo "<span>" . $row[$skill . 'lvl'] . "</span>";
    echo "</span>";
    echo "<span class=\"columnXp\">";
    echo "<span>" . $row[$skill . 'xp'] . "</span>";
    echo "</span>";
    echo "</a>";
    $rank++;
    } 
mysql_close($con);
?>

2 Answers2

0

Your query is failing and therefore not producing a query resource, but instead producing FALSE.

To reveal what your dynamically generated query looks like and reveal the errors, try this:

$result2 = mysql_query($result) or die($result."<br/><br/>".mysql_error());
0

Your problem lay here:

 $result = mysql_query("SELECT * FROM skills WHERE ". $PLAYERS_TO_NOT_SHOW . " ORDER BY " . $skill . "lvl DESC, " . $skill . "xp DESC");

beacuse mysql_query function return boolean value i suposse is false. From php.net manual http://pl1.php.net/mysql_query mysql_query function return:

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

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, 
mysql_query() returns TRUE on success or FALSE on error.
ZiupeX
  • 340
  • 3
  • 13