select block block lines from a range of 10 in 10 by looping in the query? [duplicate]

-2

I have a table of 500 thousand precise lines of this 500 thousand lines only of 1000 in 1000 for example select * from table limit 1000 offset 0; the range would be to stop at 1000 and then make another select starting from 1001 to 2000 for example only I need to do this once in a php script

    
asked by anonymous 02.03.2016 / 19:12

1 answer

1
<?php 

var $quantidadeRegistro = 5000; //quantiade registro no banco

var $limit = 1000; 
var $offset = 0;

var $select = "";

//criar os select no banco
for($i = 1; $i <= $quantidadeRegistro ; $i += 1000){ 
    $select = $select + "select * from [tabela] limit " . $limit . " offset " . offset;
}

$offset = $limit;

if($quantidadeRegistro > $limit){
    $limit = $limit + 1000;
} else {
    $limit = $limit + ($quantidadeRegistro - $limit);
}

if($quantidadeRegistro > $limit){
$limit = $limit + 1000;
} else {

}

}

I think it's more or less what you need!

    
02.03.2016 / 19:51