search

Home  >  Q&A  >  body text

How does MySQL PHP read data cyclically from the database in batches?

If five items are read from the database each time, how should the program continue to loop until all loops are completed.
add a

$a = true;
//然后用while循环
//在数据库里设计个字段,为判断有没有取出来过这条数据的字段,默认为没取出来过
//然后用foreach把每次取出来的每条数据都标记为已取出过,直到所有数据都被标记为已取出过来,循环停止。

Is this logic correct?

迷茫迷茫2831 days ago839

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-07-01 09:13:51

    You use limit. Then record the id until the id is greater than maxid, right?

    reply
    0
  • 高洛峰

    高洛峰2017-07-01 09:13:51

    You can use the principle of paging query. .

    $count = '100';//总条数
    $strip = 0;
    $num = $count/5;//循环多少次
    for($i=1;$i<=$num;$i++)
    {
     $sql = "select * from `table` order by id limit ".$strip.",5";
     $strip += 5;
    }

    reply
    0
  • Cancelreply