douzhuang6321 2012-04-29 11:26
浏览 29
已采纳

对PHP for循环如何工作感到困惑

I have a for loop that displays the first six items in a MySQL database. I then breakout to another piece of code, after which I have another for loop that displays the next six items in my database.

Though this is exactly the functionality that I wanted, I am confused as to how it works, and was hoping somebody could clarify for me. How does the second for loop know to start off where the first one left off?

My code is as follows:

for ($i = 1; $i <= 6; $i++) {
  $row = mysqli_fetch_array($result);

  $id = $row['id'];
  $title = $row['title'];
  $file = $row['file'];

  // Display items

}

The second for loop is exactly the same.

  • 写回答

1条回答 默认 最新

  • dqc22586 2012-04-29 11:29
    关注

    There is a resultset pointer that is created when you execute a query that returns a result set . Each call to mysqli_fetch_array advances the resultset pointer to next record

    When you are at the start of second for loop the result set pointer is pointing the 7th record

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制