Reputation: 28284
We are using jquery for pagination. We are pulling millions of records from the database and then th jquery does the pagination on the front end. that is a very slow process. Can someone advice us of a solution in php and jquery where we pull 50 records at a time? Thanks
Upvotes: 6
Views: 1174
Reputation: 1
http://gloryplus.com/index.php?route=product/product&path=81&product_id=176
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\">next >></a>";
Upvotes: 0
Reputation: 676
A simple jquery pagination for table, div and li you can see it from Simple Jquery Pagination
Upvotes: 0
Reputation: 16543
Yes, you should use ajax instead of retrieving the whole thing, try this:
$.get("path/to/page.php", { param1: "myParam1", page: "pagenumber" },
function(data){
$('#datacontainer').html(data);
});
For further information on the $.get
function read this: http://api.jquery.com/jQuery.get/
Upvotes: 3
Reputation: 663
Do you really need/want to use jquery for the pagination aswell?
On the php side you can work out the row number to start from (using page_number-1 * number_of_rows_per_page) so page 1 will start at row 0, page 2 at 50. That way you only grab 50 rows at a time.
jQuery can then be used to style the table and or send an ajax request to the script to retrieve the specific rows.
$page_number = $_GET['page']; //Could POST this if u want to keep your urls tidy
$num_rows_per_page = 50;
$start_row = ($page_number -1) * $num_rows_per_page;
//This will get just the specified number of rows
$sql = "SELECT * from mytable LIMIT $start_row, $num_rows_per_page"
Upvotes: 6