Jump to content

Recommended Posts

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.

 

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']);
}

- 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. 

 

Wow, nice long post. :D

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.