PHP重置mysqli_result [英] PHP Reset mysqli_result

查看:43
本文介绍了PHP重置mysqli_result的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次向堆栈溢出发帖,我希望有人可以帮助我弄清楚我做错了什么. 我有以下一段代码在重置$ row数组时遇到问题.这是一个嵌套循环,$ row第一次起作用,然后在其他循环上为空白...有什么想法吗?

It's my first time posting to stack-overflow, i'm hoping someone can help me figure out what i'm doing wrong. I have the following piece of code that I am having problems resetting the $row array. It's a nested loop, $row works the first time, then is blank on additional loops... any ideas?

/**Setup local variables with passed data**/
$ing = $this->getVariable('ingredients');
$row = $this->getVariable('unitdrop');
$unit= $this->getVariable('unit');

/**Start Displaying data**/
if (!$ing) {print("No ing");}
else
{while ($i = $ing->fetch_array())
{
/**Display $ing Data**/
    if (!$row) {print("No data row");}
    else
    {while($p = $row->fetch_array())
        {
        /**Display $row Data**/
        } 
    }
reset($row); // <-- Does not reset $row to first record
}

感谢您的协助!

推荐答案

reset重置数组.在您的情况下, $ row 是类mysqli的对象.请使用方法 mysqli :: data_seek (请参见链接中的示例).我猜应该是$row->data_seek(0);.

reset resets an array. $row is an object of class mysqli in your case. Use the method mysqli::data_seek instead (see the example in the link). Should be $row->data_seek(0); I guess.

这篇关于PHP重置mysqli_result的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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