修复我的MySQL主要错误后,我现在认为网站上的PHP存在问题,包括我创建的MySQL表。我收到了文字:
Website link directly to error
警告:mysql_fetch_array()要求参数1为资源,在第258行的/home/content/26/10406626/html/highscore/index.php中给出布尔值
这是我在文件中 $ result 的地方:
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");
}
这是第254至278行: 显然,第258行是 *而($ 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);
?>
答案 0 :(得分:0)
您的查询失败,因此不会生成查询资源,而是生成FALSE。
要显示动态生成的查询的内容并显示错误,请尝试以下操作:
$result2 = mysql_query($result) or die($result."<br/><br/>".mysql_error());
答案 1 :(得分:0)
你的问题在这里:
$result = mysql_query("SELECT * FROM skills WHERE ". $PLAYERS_TO_NOT_SHOW . " ORDER BY " . $skill . "lvl DESC, " . $skill . "xp DESC");
beacuse mysql_query函数返回布尔值i suposse为false。来自php.net手册 http://pl1.php.net/mysql_query mysql_query函数返回:
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.