return rows from a 10-by-10 block query by making a loop in this query? [closed]

-2

Person, I have a problem. For example, I need to make a SELECT in a huge table, and I want it to return rows in the range of 10 by 10.

For example: 1,2,3,4,5,6,7,8,9,10 to 11,12,13,14,15,16,17,18,19,20 , and so on.

Case study:

I have a table of 500 thousand lines. I need this 500 thousand lines, only 1000 in 1000:

select * from tabela limit 1000 offset 0;

The range would be to stop at 1000, and then make another select starting at 1001 and going to 2000.

I just need to do this once in a PHP script.

It is more or less how to make a pagination more serious than being automatic, the select would have to execute that block from 1000 to 1000 until there are no more rows in the table

    
asked by anonymous 02.03.2016 / 18:07

1 answer

2
<?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);
}

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

    
02.03.2016 / 20:28