duanleixun2439 2014-12-02 18:48
浏览 282
已采纳

Sql数组只显示第一个结果

I want to put the results in variables seperately but for that I will need to be able to call them separate. Right now I have this query that retrieves 6 results (tested with mysqli_num_rows). But when I print it, it will only shows the first row from my 6 results.

$result =  mysqli_query ($con, $query) or die("FOUT: " . mysqli_error($con));

echo "<p>mysqli_num_rows($result)</p>";

$row = mysqli_fetch_row($result);
print_r($row);
mysqli_free_result($result);

Results from

print_r($row) = 

Array ( [0] => Iran [1] => 28 )
  • 写回答

4条回答 默认 最新

  • dou12754 2014-12-02 18:53
    关注

    To get all rows you will need to do something like:

    $rows = array();
    while($row = mysqli_fetch_row($result)) {
       $rows[] = $row;
    }
    // $rows will now contain all rows in the result set
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64