Jump to content

A new puzzle - Pagination and multiple categories ?!


Jax2

Recommended Posts

Having another classic brain fart here and thought I'd pose a small puzzle to you guys and see what you think. Hard to even explain this, so bear with me.

 

For the sake of this thread, let me just say I have a single php page set up that displays videos from my database. There are 4 categories and I use a switch statement to determine which videos to pull up based on what the user chose. ALL - funny, scary, cool and sad. Just examples.

 

Now, I've created pagination so that it should be limiting the videos to 5 per page, just a test here.

 

I call the videos using a while loop - I select all videos where type = (funny, scary, cool, sad or all videos). This has worked fine, and the correct videos show up depending on what is chosen.

 

Here is where I am running into the problem. If I have, say, 25 videos total and set the pagination to 5 per page, the pagination is working correctly, it is showing there should be 5 pages.

 

Unfortunately, each page is showing all 25 videos.

 

What I am thinking is that it is reading correctly from the database (Ok, there are 13 scary videos, so that would be 3 pages) and creates the page. However, once that is done, it reads the rest of the code and hits my while loop that says to get ALL of the scary videos and show them on that page.

 

So I need to determine how I can limit how many videos are shown, starting from which record depending on the page.

 

I.e. page one would show videos tagged with "scary" starting at the first "scary" video, finding 5 of them and returning those 5. Then on the next page, it looks and see's currentpage=2 and says okay, now I need 6 - 10 ...

 

How would I write that out in my SQL statement? Any suggestions?

 

Ahh yeah, one thing, the videos are sorted by "CONTENT_ID" ... I figured I could do something like starting at record # (whatever, determined by current page number) and limit returned videos by 5, but the problem is, the video types have all different content_id numbers, as in, not in a row, so I'm not sure how to say what record number to start at. Very confusing.

 

You should take a look at my pagination class. It does all the hard work for you, and I can guarantee it will only pick out the videos you want.

 

If you need any help in getting it working with your code let me know and I'll see what I can do :)

Archived

This topic is now archived and is closed to further replies.

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