嗨,我试图用"user1"和"score1"等索引填充数组以返回到函数。
我的代码:它出现未识别的变量错误
$query = 'select * from users order by score desc';
$result = mysql_query($query) or die (mysql_error());
$highscore = array();
$count = '0';
while($row = mysql_fetch_array($result))
{
$count++;
$highscore = array('user' . $count => $row['username'], 'score' . $count => $row['score']);
}
return $highscore;
当您
想要使用数值时,您应该使用它们。您使用了零 ('0'
) 的字符串表示形式
$count = 0;
$highscore = array();
while($row = mysql_fetch_array($result))
{
$count++;
$highscore['user' . $count] = $row['username'];
$highscore['score' . $count] = $row['score'];
}
如果你想要"高分",你可能想使用 max 并只返回 1 行。