jaymc Posted July 22, 2009 Share Posted July 22, 2009 Does anyone have any nice prebuilt, re-useable functions that handle creating html numbed paged links to toggle between mysql result sets e.g mysql returns 500 rows, you split that up into 50 pages, 10 rows Im trying to avoid ugly code each time I need to do this, would be nice to have a reusable function that can handle returning the html paged links as well as maintain query strings I've seen a few on google but they arnt too great. Also the PHP_Pear is not to hot either How do you experts on here go about this Quote Link to comment https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/ Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 Use a framework Most of them have pagination libraries. I use Kohana and it has a nice pagination library. Quote Link to comment https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/#findComment-880536 Share on other sites More sharing options...
jaymc Posted July 22, 2009 Author Share Posted July 22, 2009 I don't really want to use a framework just for this I'd prepare to just have it as a function file and include when I need it. I don't need the framework features. Quote Link to comment https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/#findComment-880538 Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 You could always use the Zend paginator: http://framework.zend.com/manual/en/zend.paginator.html Quote Link to comment https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/#findComment-880545 Share on other sites More sharing options...
jaymc Posted July 22, 2009 Author Share Posted July 22, 2009 No its still to heavy, I just want a nifty piece of code to run as a simple function Something that I just pass $TotalNumRows, $RowsPerPage, $UrlqueryString Quote Link to comment https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/#findComment-880546 Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 Pagination is pretty involved, I'm not sure you will ever find something that is just super simple. Quote Link to comment https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/#findComment-880549 Share on other sites More sharing options...
jaymc Posted July 22, 2009 Author Share Posted July 22, 2009 true, will have to edit a few things but would be a good start if someone has made a pretty generic function to handle it Quote Link to comment https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/#findComment-880551 Share on other sites More sharing options...
bruce080 Posted July 22, 2009 Share Posted July 22, 2009 http://www.tonymarston.net/php-mysql/pagination.html I found this link super helpful. Only about 20 lines of code and its easy to modify to make your own style from it. You'll need to be more specific if you want further help though. Quote Link to comment https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/#findComment-880646 Share on other sites More sharing options...
jaymc Posted July 23, 2009 Author Share Posted July 23, 2009 Ah I ended up making my own, I guess the best is one that works for you. Here it is // ########################################### // FUNCTION TO GENERATE DROP DOWN PAGE LINKS # // ########################################### function page_links($rowsPerPage, $totalRows, $currentRow, $url = false) { // ---------------------------------- // BUILD SELECT OPTION FOR EACH PAGE // ---------------------------------- if ($totalRows % $rowsPerPage == 0) {$offset = 0;} else {$offset = 1;} $pages = floor($totalRows / $rowsPerPage) + $offset; while ($i < $pages) { $i++; $page_from = ($i * $rowsPerPage) - $rowsPerPage; if ($page_from == $currentRow) {$selected = " SELECTED";} else {$selected = "";} $page_options .= "<option value=\"$page_from\"{$selected}>Page $i</option>"; } // ------------------------------- // REMOVE pageFrom= FROM QUERY STRING // ------------------------------- if (!$url) {$url = $_SERVER['QUERY_STRING'];} parse_str($url, $queryString); unset($queryString['rowFrom']); $urlQuery = rawurldecode(http_build_query($queryString)); // -------------------------------------- // PUT THE DROP DOWN TOGETHER AND RETURN // -------------------------------------- $page_jump = "<SELECT style=\"width:80px\" id=\"quick_jump_menu\" OnChange=\"ajaxopen('#center_content', '$_SERVER[sCRIPT_NAME]?$urlQuery&rowFrom=' + this.value)\">$page_options</SELECT>"; return $page_jump; } Quote Link to comment https://forums.phpfreaks.com/topic/166997-solved-pagination-html-links/#findComment-880918 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.