0

I have a 500 item data array, taken from the partner Database . I have finished pagination .

But the counterpart Database is very weak if it loads 500 item at a time, it is very heavy. Is there a way to finish downloading 30 item and then downloading the next 30 item?

To not load 500 items times .

Please help me, thank you !

Strawberry
  • 33,750
  • 13
  • 40
  • 57
json
  • 67
  • 4
  • 15

1 Answers1

0

Load your first 30 datasets from the database, Then when the page has finished loading use ajax to send a request to the server to fetch the remaining records in batches of 30.

// ajax call to PHP script for processing.
var n= 1;
(function yourfunction () 
{

    $.ajax
    ({
        url:"yourphpscript.php",
        type:"POST",
        data:{'n':n},
        success:function(response)
        {
                        
            $("#the-display-area").append(response); 
            n+=1;//counter increement
        }
     })
})();

//PHP code to accept the post data of n from the ajax call and use it to query the 
database 

$n=$_POST["n"];
$n=$n*30;

    
$query = "SELECT * FROM yourtable LIMIT 30 OFFSET $n";
boonu
  • 339
  • 2
  • 5