return rows of a 10-by-10 block query by looping this query?

Asked

Viewed 167 times

-2

Person, I have a problem. For example: I need to make a SELECT on a huge table, and I want you to return lines in the range of 10 in 10.

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

Practical case:

I have a table of 500,000 lines. I need this 500,000 lines, only every 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.

Only I need to do it once in a PHP script.

is more like making a pagination more would be to be automatic, select would have to run that block from 1000 in 1000 until there are no more rows in the table

  • interval would be what? take a break of X seconds? Display each block of 10 in 10 without taking breaks?

  • You may be talking about paging. http://answall.com/questions/26303/como-fazer-pagina%C3%A7%C3%A3o-php-e-mysql

  • Your question is missing useful information. Post the code of what you have tried to do, if you have.

  • 1

    LIMIT/OFFSET if your bank allows or equivalent.

  • Vinicius, you were the one who edited it into another account?

  • I got that question because it was suggested to me in the analysis queue (in a test I was flunked out of once I voted to keep it open). The test tells me to stop, look and listen because the question has problems. Doing what was asked, the question in the current version does not seem to have understanding problems (and I understand very little of SQL). What the AP needs is to consult the lines slowly, in an informed quantitative range. @Wallacemaxters understood and even suggested a response about paging. If?

Show 1 more comment

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 that’s about what you need!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.