J
J
Jodes2014-12-15 20:44:13
PHP
Jodes, 2014-12-15 20:44:13

There is a big table. How to select from it all the data in a cycle, in batches of 10 records?

It is clear that you need to use LIMIT and OFFSET, but I don’t understand how to shift OFFSET?
Explain the principle or poke into a code example.
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2014-12-15
@Jodes

<?php
$limit = 10000;
$offset = 0;
do {
$data = $db->query("SELECT * FROM `tbl` ORDER BY `id` ASC LIMIT $limit OFFSET $offset")->fetchAll();
$offset += count($data); 
}
while(count($data));

F
FanatPHP, 2014-12-15
@FanatPHP

Not necessary.
How much data you need - so much and request, all at once, without any limits.

J
Jodes, 2014-12-15
@Jodes

I would like to leave it here.
Thanks everyone for the replies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question