PHP returning strange row counts
i am working with a very large data set (786,432 rows to be precise).
So, to prevent memory limits I want to loop over the data set in piles of 50,000 rows, so to test this out I thought I would try:
function test(){
$start = 0;
$end = 50000;
$q = $this->db->select('uuid')->from('userRegionLink')->limit($end, $start)->get();
$i = 0;
while($q->num_rows() != 0){
echo 'Round: '.++$i.'<br />';
echo 'Rows: '.$q->num_rows().'<br />';
echo 'Start: '.$start.'<br />';
echo 'End: '.$end.'<hr />';
$start = $end;
$end = $end+50000;
$q = $this->db->select('uuid')->from('userRegionLink')->limit($end, $start)->get();
}
}
But my results are very strange: look at round 9 and below.
What is causing this?
Round: 1
Rows: 50000Start: 0End: 50000
Round: 2Rows: 100开发者_StackOverflow社区000Start: 50000End: 100000
Round: 3Rows: 150000Start: 100000End: 150000
Round: 4Rows: 200000Start: 150000End: 200000
Round: 5Rows: 250000Start: 200000End: 250000
Round: 6Rows: 300000Start: 250000End: 300000
Round: 7Rows: 350000Start: 300000End: 350000
Round: 8Rows: 400000Start: 350000End: 400000
Round: 9Rows: 386432Start: 400000End: 450000
Round: 10Rows: 336432Start: 450000End: 500000
Round: 11Rows: 286432Start: 500000End: 550000
Round: 12Rows: 236432Start: 550000End: 600000
Round: 13Rows: 186432Start: 600000End: 650000
Round: 14Rows: 136432Start: 650000End: 700000
Round: 15Rows: 86432Start: 700000End: 750000
Round: 16Rows: 36432Start: 750000End: 800000
It looks like $end is not a global offset just number of records to fetch (offset from $start). Try to set $end always for 50000 and changing only $start.
精彩评论