dongmi8980 2011-05-11 01:23
浏览 48

当mysql_num_rows在php中返回4时,mysql_fetch_array不返回任何内容

I have some code in php that accesses a mysql database in sorted order, then prints out the info in a table. However, whenever it calls mysql_fetch_array, the function returns nothing, even though mysql_num_rows is 4. That is, if I do $row=mysql_fetch_array($result);, $row['name'] is "" even though there is most certainly a name column in the table. A snippet of the code is below:

<?php
include_once("include.php");
$number=0;
if(!isset($_GET['scores'])) {
   $number=10;
}
else if((int )$_GET['scores']>100) {
   $number=100;
}
else if((int) $_GET['scores']<0) {
   $number=10;
}
else {
   $number=(int) $_GET['scores'];
}

$con=mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $con);
$result=mysql_query("SELECT * FROM ".$dbtable_scores." ORDER BY score DESC,date;", $con);
$num=1;
echo("<table>");
echo("<tr><td>position</td><td>Name</td><td>score</td><td>date</td></tr>");
while($row=mysql_fetch_array($result) && $num<=$number) {
   echo("<tr>");
   echo("<td>".$num."</td>");
   echo("<td>".$row['name']."</td><td>".$row['score']."</td><td>".$row['date']."</td>");
   echo("</tr>");
   $num++;
}
echo("</table>");
mysql_close($con);
?>

I have checked the query in mysql cli, and it seems to work fine. However, as you will see if you go to http://mtgames.org/index.php, the table has only the numbers that are not generated from mysql. The mysql table has columns name, score, date, among others. Any help is appreciated. Thanks, -Michael.

  • 写回答

2条回答 默认 最新

  • dongliao1860 2011-05-11 01:27
    关注

    maybe try mysql_fetch_assoc($result) opposed to mysql_fetch_array($result)?

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀