开发者

jquery pagination

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


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"


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/


I've used jqGrid for an ASP.NET MVC app but they do a php version which should be good to use.


A simple jquery pagination for table, div and li you can see it from Simple Jquery Pagination


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>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜