paging in php [modified]
-
hi, i would like to know how i can paging in php with mysql. i want next, pre , first, last and combo box(listbox) where total number of pages shows in the combo box and when i click on page number than show records.
modified on Thursday, April 23, 2009 7:39 AM
-
hi, i would like to know how i can paging in php with mysql. i want next, pre , first, last and combo box(listbox) where total number of pages shows in the combo box and when i click on page number than show records.
modified on Thursday, April 23, 2009 7:39 AM
-
hi, i would like to know how i can paging in php with mysql. i want next, pre , first, last and combo box(listbox) where total number of pages shows in the combo box and when i click on page number than show records.
modified on Thursday, April 23, 2009 7:39 AM
Basically you are going to use a technique similar to that in a previous post: http://www.codeproject.com/script/Forums/View.aspx?fid=1640&msg=1742252[^] Your sql queries will use the LIMIT keyword which specifies the number of pages a query is broken into and how many results to display. In MySQL it's like this SELECT COUNT(*) AS total_pages FROM `table01`; $result = $dbHandle->query($sql); $row = $result->fetch_assoc(); $total_rows = $row['total_pages']; //You'll need to calculate the end page, to display links to prev and next $end_page = ceil($total_rows/$span); SELECT * FROM `table01` LIMIT 0, 10; where 0 is the current page being viewed (0 indexed) and 10 is the number of elements to return ($span). in your code, the query will be: "SELECT * FROM `table01` LIMIT $cur_page, $span" and $cur_page will be a GET requested variable $cur_page = $_GET['page']; if (!$cur_page) $cur_page = 0; Now display the results of the above query. Then display the previous and next links however you like display_link("page.php?cur_page=".$cur_page--); //prev display_link("page.php?cur_page=".$cur_page++); //next You can find a nicely formatted display was found on the web: http://www.phpeasystep.com/phptu/29.html[^]