使用foreach循环,而不要同时使用myslqli_fetch_array() [英] Use a foreach loop instead of while with myslqli_fetch_array()

查看:85
本文介绍了使用foreach循环,而不要同时使用myslqli_fetch_array()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我意识到当做:

Okay, so I realize that when do:

//connection code;

//query code;

//$result= mysqli_query();

$row= mysqli_fetch_array($result);

您创建一个关联数组,其中表中的列名是相应行中数据的键.

you create an associative array where the column names from your table are the keys for the data in the respective row.

然后您可以使用:

while ($row= mysqli_fetch_array($result))
{
//code to echo out table data.
}

我的问题是,每次迭代后while循环如何转到下一行?我以为那是foreach循环的作用?

My question is how does the while loop go to the next row after each iteration? I thought that was what foreach loops were for?

推荐答案

来自

array mysql_fetch_array(资源$ result [,int $ result_type = MYSQL_BOTH]) 返回与获取的行相对应的数组,并将内部数据指针向前移动.

array mysql_fetch_array ( resource $result [, int $result_type = MYSQL_BOTH ] ) Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.

这篇关于使用foreach循环,而不要同时使用myslqli_fetch_array()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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