Forum Moderators: coopster
I'm using images for the numbers pulled from a MySQL database (I know text is better, but client wants rollover buttons). There are four categories in the portfolio, each with image and description. That part works fine.
I'm able to get just the next and prev images to work to scroll through the portfolio one item at a time, but I can't get the numbers to both display correctly or to link to the corresponding portfolio item (ie. 15 images total in portfolio, then 15 total nav images displayed in set). Ideally I'd have the next and back jump from one set to the next, not go through each item.
I know, this is probably beginner stuff, but the logic of these browsing systems seems to escape me.
I want the page to work like this:
First set:
[portfolio image] [description]
[Prev not displayed] 1 2 3 4 5 6 7 8 Next Page
Second set and so on to the end:
[portfolio image] [description]
Prev Page 9 10 11 12 [Next not displayed]
Where's a good place to start?
do you have these items in pages of thumbnails, with x per page? or is there only one item per page? the user clicking "next" expects to see a page just like the current one, but with all new stuff on it. So if you have 15 items per page, you skip forward 15 items. If there are only one per page, you skip to the next one.
page 1 shows items 0-14
page 2 shows items 15-29
page 3 shows items 30-44
etc.
I am annoyed by badly paginated data where the first page has 1-10, then the next page shows 2-11. Some of the WebTrendsLive reports are like that.
I do paginated results with only one variable in the querysting: "start". Your script should know two other things: the total number of items ($total) and items per page ($ipp)
start at $start and show the next $ipp items. The "next" link goes to the same script with $start+$ipp, "prev" goes to $start-$ipp.
if you're grabbing stuff from a database, use the LIMIT clause wisely
obviously then, if $start==0, you don't show the "prev" link. Likewise, if $start>($total-$ipp), you don't need to show the "next" link.
if $start<0, set $start=0.
if $start>$total, set $start=$total-$ipp.
That keeps people from skipping past the ends of your data set.
paginating data results is something every programmer should do once with hands-on coding, it's a great place to make a whole bunch of mistakes and learn to think logically about sequences and off-by-one errors [clueless.com].
good luck!
think of what your user will expect to happen when they press "next" or "previous"...I am annoyed by badly paginated data where the first page has 1-10, then the next page shows 2-11.
Yes, only one item per page.
I'm a fan of Jakob Nielsens quest to make the web a user friendly place (though I'm also a fan of design with a little style :)
I do paginated results with only one variable in the querysting: "start".
Good advice. Keep links clean and simple.
if you're grabbing stuff from a database, use the LIMIT clause wisely
Would you say it's best to avoid the LIMIT clause? I've heard things like, "do the database functions in the database and page functions in the scripting". This seems to blur the line, it's both a display issue and a database issue.
paginating data results is something every programmer should do once with hands-on coding, it's a great place to make a whole bunch of mistakes and learn to think logically about sequences and off-by-one errors.
This is very helpful and concise. Thank you. No doubt I'll be makin' those mistakes today...