Fluoresce Posted February 24, 2009 Share Posted February 24, 2009 Hi, guys. I was wondering if anyone knew where I could find a pagination script which allows a user to choose the number of results to display per page. And since most scripts just have 'First', 'Prev', 'Next' and 'Last' buttons, I would also like the script to have a drop-down menu which will allow a user to jump to any page. Is anyone aware of such a script? Link to comment https://forums.phpfreaks.com/topic/146701-solved-pagination-with-function-to-choose-number-of-results-per-page/ Share on other sites More sharing options...
cooldude832 Posted February 24, 2009 Share Posted February 24, 2009 First off this isn't google we help ppl with programing issues not how to use google issues. Secondly post what you have written if you got nothing then we can give you no feedback. Link to comment https://forums.phpfreaks.com/topic/146701-solved-pagination-with-function-to-choose-number-of-results-per-page/#findComment-770201 Share on other sites More sharing options...
Fluoresce Posted February 24, 2009 Author Share Posted February 24, 2009 Dude, chill. I have obviously already searched Google for such a script. I couldn't find one, which is why I thought I would ask the pros in a PHP forum. Here's what I've already got: <?php $conn = mysql_connect('localhost', 'hidden', 'hidden') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('hidden', $conn) or trigger_error("SQL", E_USER_ERROR); $query = "SELECT COUNT(*) FROM . . ."; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // end else $rows_per_page = 5; $lastpage = ceil($numrows/$rows_per_page); $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } // end if if ($pageno < 1) { $pageno = 1; } // end if $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; $query = "SELECT . . . $limit"; $result = mysql_query($query, $conn) or trigger_error("SQL", E_USER_ERROR); if(mysql_num_rows($result) >= 1) { if ($pageno == 1) { echo " "; } else { echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pageno=1'>First</a> "; $prevpage = $pageno-1; echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>Prev</a> "; } // end else echo " $pageno of $lastpage "; if ($pageno == $lastpage) { echo " "; } else { $nextpage = $pageno+1; echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>Next</a> "; echo " <a class=\"pagination\" href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>Last</a> "; } // end else while($row = mysql_fetch_assoc($result)) { echo "Results . . ." } // end while } // end first if else { echo "<p>None</p>"; } ?> This code produces 'First', 'Prev', 'Next' and 'Last' buttons. As such, if there are 50 pages and a user wants Page 36, s/he will have to click all the way there. I therefore want to include a drop-down menu which users can use to choose the page that they want. This code also produces five results per page. I can change that, of course, but I want the users to be able to change it manually. Can these alterations be incorporated into the current script? Or, should I continue looking for a new script? Link to comment https://forums.phpfreaks.com/topic/146701-solved-pagination-with-function-to-choose-number-of-results-per-page/#findComment-770314 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.