PHP Reset mysqli_result

两盒软妹~` 提交于 2019-12-13 03:57:42

问题


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
}

Thanks for any assistance!


回答1:


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.



来源:https://stackoverflow.com/questions/11621029/php-reset-mysqli-result

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!