webref.eu Posted August 25, 2008 Share Posted August 25, 2008 I'm looking for a good solution to page records from MySQL, please give me links to any solutions that you have found to work well. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/121238-links-to-good-paging-solutions-please/ Share on other sites More sharing options...
DarkWater Posted August 25, 2008 Share Posted August 25, 2008 You mean pagination? There's a tutorial on the main page of this site I believe. Quote Link to comment https://forums.phpfreaks.com/topic/121238-links-to-good-paging-solutions-please/#findComment-624992 Share on other sites More sharing options...
webref.eu Posted August 25, 2008 Author Share Posted August 25, 2008 OK, thanks, I'll take a look. Anymore suggestions or advice on best practice? Thanks All. Quote Link to comment https://forums.phpfreaks.com/topic/121238-links-to-good-paging-solutions-please/#findComment-625001 Share on other sites More sharing options...
ninedoors Posted August 25, 2008 Share Posted August 25, 2008 I use this one. http://www.mis-algoritmos.com/2007/03/16/some-styles-for-your-pagination/ Nick Quote Link to comment https://forums.phpfreaks.com/topic/121238-links-to-good-paging-solutions-please/#findComment-625109 Share on other sites More sharing options...
webref.eu Posted August 26, 2008 Author Share Posted August 26, 2008 OK, so I just read: http://www.phpfreaks.com/tutorial/basic-pagination which was a great basic tutorial. This didn't have the Sort By functionality which I am looking for. Below I give a summary of what I'm looking for, so please make any further suggestions for tutorials I can look at. Thanks. - Display 20 records per page. - Next Page Link. - Last Page Link. - First Page Link. - Previous Page Link. - Hyperlinks to page numbers. - Sort by Rating / Review Name / Date Added. - Alternating line colours. - Nice to have: Ability to search within reviews. Easy to apply and maintain. Quote Link to comment https://forums.phpfreaks.com/topic/121238-links-to-good-paging-solutions-please/#findComment-626026 Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 This stuff really isn't that complicated...it's just like, adding a dropdown for Sort By and some Javascript to make it automatically submit the form onchange without a submit button, and the alternating line colors is basically one variable and an if statement. Colors: <?php $bg = "EEEEEE"; while ($row = mysql_fetch_assoc($result)) { $bg = (($bg == "EEEEEE") ? "FFFFFF" : "EEEEEE"); printf('<tr bgcolor="%s"><td>%s</td></tr>', $bg, $row['foo']); } Quote Link to comment https://forums.phpfreaks.com/topic/121238-links-to-good-paging-solutions-please/#findComment-626032 Share on other sites More sharing options...
.josh Posted August 26, 2008 Share Posted August 26, 2008 - Display 20 records per page. In the tutorial, $rowsperpage defines how many records to display per page. It's set at 10 as an example. All you have to do is change it to 20 or whatever else you want. - Next Page Link. - Last Page Link. - First Page Link. - Previous Page Link. - Hyperlinks to page numbers. Perhaps you should clarify, because the tutorial does provide those things. Perhaps you wanted it to "look" different? I have a sneaking suspicion that there probably isn't some prefab out there that happens to match what you have in mind, and that the only way you are going to get it to "look" the way you want, is to tweak it yourself. - Sort by Rating / Review Name / Date Added. The original pagination tutorial I did (before the site went down), included "sort by" functionality. Basically I just made the column titles links with a sortby=columnname and used the GET method to grab that and sort by that column. Like the page number, I checked to make sure it was a valid column name. You can simply do something like $columns = array('column1','column2','column3'); $default = 'column1'; // default column, in case someone tries to mess with var $sortby = (in_array($_GET['sortby'], $columns))? $_GET['sortby'] : $default; Then just throw the $sortby into the query string and you're good to go. You can hardcode the columns in there or you can make $columns dynamic by doing a show columns query or something. Entirely up to you, depending on your needs. - Alternating line colours. Darkwater covered that. It's as simple as adding a condition in the loop (ternary is good) that acts like an "on/off" switch. - Nice to have: Ability to search within reviews. This isn't really part of pagination. That's something else, and you probably won't ever find a "pagination" script that encapsulates that, simply because it's not part of pagination. You're going to have to look for tutorials/scripts that deal with searching through data/results, and incorporate it into your script as a whole. Easy to apply and maintain. You should probably look for a pagination class for that, or else convert it into a class. The tutorial was meant to teach the concepts of pagination. It's up to you as the programmer to decide how to best fit those concepts into your own program/situation. Overall, you're probably not going to find some "all-in-one" script out there that does everything you want the way you want. That's why you are there, instead of your boss or someone else. It's your job to take something and add to it or tweak it to specifications. Quote Link to comment https://forums.phpfreaks.com/topic/121238-links-to-good-paging-solutions-please/#findComment-626068 Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Wow, nice long post. Anyway, @webref.eu: Tutorials aren't meant to provide you with code that you just throw in your website to magically work, they're there to teach you the concepts for you to tweak and make exactly how you want it. Quote Link to comment https://forums.phpfreaks.com/topic/121238-links-to-good-paging-solutions-please/#findComment-626074 Share on other sites More sharing options...
webref.eu Posted August 26, 2008 Author Share Posted August 26, 2008 OK, thanks a lot for your comments, I will have a go at tweaking the script. I am a newcomer to PHP so getting these pointers really does help. Rgds Quote Link to comment https://forums.phpfreaks.com/topic/121238-links-to-good-paging-solutions-please/#findComment-626096 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.