如何迭代mysqli结果集? [英] How to iterate a mysqli result set?

查看:70
本文介绍了如何迭代mysqli结果集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想遍历以下查询的结果集:

I want to loop through the result set of the following query:

"select uid from userbase"

我目前正在使用以下循环,但是我只能得到第一个值.

I am currently employing the following loop, but I can get only the first value.

$i = 0;
$output = mysqli_query($mysqli, "select uid from userbase") or die(mysqli_error($mysqli));
while ($row = $output->fetch_array()) {
    $deviceToken = $row[$i];
    echo $deviceToken;
    $i++;
}

可能是什么问题?是fetch_array()吗?

What might be the problem? Is it fetch_array()?

推荐答案

您需要定义一个数组并将数据存储到loop内部的数组中. 使用MYSQLI_ASSOC无需增加值

You need to define a array and store your data into array inside loop . Use MYSQLI_ASSOC no need for incremented value

$deviceToken=array();
while ($row = $output->fetch_array(MYSQLI_ASSOC)) {
    $deviceToken[] = $row['uid'];
}
print_r($deviceToken);
for($i=0;$i<=count($deviceToken);$i++){
echo $deviceToken[$i];
}

这篇关于如何迭代mysqli结果集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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