Connecting Tech Pros Worldwide Help | Site Map

Rotational view of paginated listings

Member
 
Join Date: Nov 2007
Posts: 61
#1: 2 Weeks Ago
I need to change an existing listings page with pagination.
Each page shows 10 listings and they are ordered by the date they are added to the site.

Now recently added listings show up in the first page. I need to get all the listings to come on the first page by rotating the showing of listings perhabs each day (each page should only show 10 listings).

Thus first day showing first 10 listings in the first page and the next day showing the next 10 listings and this should continue in a rotational manner.

I thought of using Random option in mysql query, but since it has pagination this option wouldn't workout.

Is there any simple and efficient way to do this (though I am not proposing any complex solution either)

Thanks Geeks
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#2: 2 Weeks Ago

re: Rotational view of paginated listings


Don't understand fully, but what code do you have so far and why isn't it working?
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,743
#3: 2 Weeks Ago

re: Rotational view of paginated listings


Quote:

Originally Posted by samatair

Thanks Geeks

Since this is what you do for a profession as well, I assume you are including yourself in that "geeks" remark, right?
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,094
#4: 2 Weeks Ago

re: Rotational view of paginated listings


From what I understand the total list (all items in the table) varies. so this week you may have a 100, next week 200 etc and it may decrease as well. But each day you want to show the "next" 10 items, instead of a random 10 item.

But for a random 10 item that is still ordered by date, you could do ORDER BY RAND(), your_date_field ASC LIMIT 10.
(To order by multiple fields in MySQL just put a comma between each field).

However if you want to completely forget the random idea, you could try a more complicated way, see below:

If you want to cycle through the pages in order one page a day, then you have to use a different method than the sql rand(). You have to store a page number in a text file and the date (timestamp).

Your code logic should do this:

1. Read the text file and extract the timestamp and the page number
2a. If the timestamp is of today, use the page number for your SQL LIMIT pagation
2b. If the timestamp is not of today (it's in the past), write to the file with today's date and increase the page number by one*

* Of course you need to make sure you're page number doesn't reach the max number of pages, if it does (i.e. the SQL returns empty results) reset the page number value to 1.

I'm sure you're smart enough to write the code for the above logic, but let us know if you get stuck somewhere.



Dan
Member
 
Join Date: Nov 2007
Posts: 61
#5: 2 Weeks Ago

re: Rotational view of paginated listings


Hi dlite922,
First i am thankful to you for providing me with two types of solution.

The first one using RAND mysql option, it surely selects listings randomly. But when you use it in pagination each time it will selects listings randomly. i.e. when the user clicks on the 2nd page it will infact select 10 random listings, so the user will not be viewing the next 10 listings, but randomly picked listings. that shouldn't happen.

If the pagination isn't there this would be the simple and perfect solution.

The second ofcourse impressed me, using a text file to store the page number and increment it as each day progress and when all the pages are shown, start over again.

In this solution I have only one problem. When the user clicks the listings page, by default it is on the first page. As with the solution on the 3rd day, the user will be landing on the 3rd page, but I need to show them that they are infact on the 1st page. And ofcourse we know that we are showing the 3rd page today and 4th tomorrow, but the user shouldn't.

If there is a way to get around this, then this should work as breeze for me. Meanwhile, I will try making this work for me and if I get it I will post the info..

Thank you very much for clearly explaining the process.

Samatair
Member
 
Join Date: Nov 2007
Posts: 61
#6: 2 Weeks Ago

re: Rotational view of paginated listings


Quote:

Originally Posted by tlhintoq View Post

Since this is what you do for a profession as well, I assume you are including yourself in that "geeks" remark, right?

Yes. Ofcourse we all share it :)
Member
 
Join Date: Nov 2007
Posts: 61
#7: 2 Weeks Ago

re: Rotational view of paginated listings


Quote:

Originally Posted by TheServant View Post

Don't understand fully, but what code do you have so far and why isn't it working?

I have a normal pagination code which shows 10 listings per page and the latest added listings are shown first. now instead of showing the latest listings first, need to show listings that are randomly picked or as described by dlite922. Thanks for your interest in this.
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,094
#8: 1 Week Ago

re: Rotational view of paginated listings


Quote:

Originally Posted by samatair View Post

Hi dlite922,
First i am thankful to you for providing me with two types of solution.

The first one using RAND mysql option, it surely selects listings randomly. But when you use it in pagination each time it will selects listings randomly. i.e. when the user clicks on the 2nd page it will infact select 10 random listings, so the user will not be viewing the next 10 listings, but randomly picked listings. that shouldn't happen.

If the pagination isn't there this would be the simple and perfect solution.

The second ofcourse impressed me, using a text file to store the page number and increment it as each day progress and when all the pages are shown, start over again.

In this solution I have only one problem. When the user clicks the listings page, by default it is on the first page. As with the solution on the 3rd day, the user will be landing on the 3rd page, but I need to show them that they are infact on the 1st page. And ofcourse we know that we are showing the 3rd page today and 4th tomorrow, but the user shouldn't.

If there is a way to get around this, then this should work as breeze for me. Meanwhile, I will try making this work for me and if I get it I will post the info..

Thank you very much for clearly explaining the process.

Samatair

Ok, this is a challenge but I think we don't really /need/ to be on page one, just pretend it's page one right?

so I would take the value of the page for a particular day (let's say for example day 3 thus page 3) and subtract it from itself and add one (3-3+1) when displaying it for the user.

formula:

current page number - day off set + 1 = viewable page number.

I'm writing this as I go so let's check to see if it works.

The user then presses the "next page" button and I think the following two things should happen according to that formula:

1. In the SQL page 4 is shown, because as far as the application is concerned you were on page 3.

2. In the display, your formula's values would be 4-3+1 = 2. Thus the user see that he's on page 2 (when he's actually on page 4)

Question is, what happens when you go the end. Let's say there is a total of 10 pages 10-3+1 would put you at page 8. User viewed actual pages 3 through 10 which equals displayed page numbers 1 through 8. so how does he view page 1 and 2 (which to the user should display page 9 and 10).

Your application code should have a rotational pagination (meaning whenever you reach the last page, it automatically goes back to page one). so now you have these values to work with to get page 9.

3 = the day/page offset
1 = the true page number

putting this in our original formula would rend 1-3+1 = -1. AHA!!

Here's the solution. Whenever this calculated page number the user sees is less than 1 ADD the total number of pages to it. In this case -1 + 10 = 9. Voila!

So on for page Ten: 2-3+1= 0 + 10 = 10

I just thought of this on-the-fly. Does anybody see a fault in it?




Dan
Reply

Tags
listings, ordering