Paul Ruiz
Paul Ruiz

Reputation: 2436

MySQL + PHP: Pull down 1000 entries at a time, increment to next 1000, repeat

Good morning!

I'm trying to do something that should be fairly simple, but I haven't been able to find a working answer. I'm trying to pull down entries 0-999 from a table, then 1000-1999, 2000-2999, etc. Here's what I've got so far, but it's still pulling down 0-999+ as it increments

for($k = 0; $k < 10000; $k += 1000)
{
    $query = "select * from TABLENAME LIMIT 1000 OFFSET " . $k;
        .....
}

Upvotes: 0

Views: 180

Answers (2)

chandresh_cool
chandresh_cool

Reputation: 11830

$start = 0;
$end = 0;
for($k = 0; $k < 10000; $k += 1000)
{

   $flag = $start+999;
   $end = 1000;
    $query = "select * from TABLENAME LIMIT $start,$end";

    .....
   $start =  $flag+1;
}

Upvotes: 0

Stephan
Stephan

Reputation: 8090

Try this:

for($k = 0; $k < 10000; $k += 1000)
{
    $query = "select * from TABLENAME LIMIT {$k},1000";
        .....
}

Upvotes: 3

Related Questions