Sql数组只显示第一个结果 [英] Sql array only showing first result

查看:44
本文介绍了Sql数组只显示第一个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将结果单独放在变量中,但为此我需要能够将它们分开调用.现在我有这个查询检索 6 个结果(用 mysqli_num_rows 测试).但是当我打印它时,它只会显示我的 6 个结果中的第一行.

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);

来自

print_r($row) = 

Array ( [0] => Iran [1] => 28 )

推荐答案

要获取所有行,您需要执行以下操作:

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

这篇关于Sql数组只显示第一个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆