473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Rotational view of paginated listings

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
Nov 6 '09 #1
7 1856
TheServant
1,168 Expert 1GB
Don't understand fully, but what code do you have so far and why isn't it working?
Nov 6 '09 #2
tlhintoq
3,525 Expert 2GB
Thanks Geeks
Since this is what you do for a profession as well, I assume you are including yourself in that "geeks" remark, right?
Nov 6 '09 #3
dlite922
1,584 Expert 1GB
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
Nov 6 '09 #4
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
Nov 8 '09 #5
@tlhintoq
Yes. Ofcourse we all share it :)
Nov 8 '09 #6
@TheServant
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.
Nov 8 '09 #7
dlite922
1,584 Expert 1GB
@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
Nov 9 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Erik Lechak | last post by:
Hello all, Is there anyone out there that has written anything in python to download tv listings (no XML)? All the tv listing stuff that I can find is way too complex for my taste (includes...
9
by: sonu | last post by:
I want to develop a application from where we can select files from a tree view Directly like window explor. Please help me
1
by: PengYu.UT | last post by:
I need to do rotational shift on bitset. But I couldn't find that operation in the standard. Is there any workaround or other packages to do this? Thanks, Peng
1
by: rabidusv | last post by:
As I understand it, the unsigned long type is 4 bytes. Also, the bitwise shift (<<) is a zero-fill shift as opposed to a rotational shift. However when I shift, the value seems to be rotating, as...
5
by: Robert Latest | last post by:
Hello, if HTML authoring includes HTML autogeneration, this request is on-topic. Otherwise please forgive me and point me in the right direction. I'd like to make a bunch of dirs full of files...
2
by: milo1955 | last post by:
I have a form that passes a single variable via the GET function to a mysql databse query with the results paginated. The first page of the results work fine, but the link to the second page yields...
0
by: Paul McGuire | last post by:
Here is some semi-obfuscated Python, to generate rotational palindromes: from random import choice base = "sznuoxpqbdMWOINZXSH" rot = dict(zip(base,"szunoxdbqpWMOINZXSH")) for i in...
4
by: Name Withheld | last post by:
OK i know this is a 101 question but... ASP.NET/VB.NET ListingItems() as string I need a nested array of Listings().ListingItems() so i can read a text file and split each line and insert...
6
by: radhikams | last post by:
Hi All Can anyone help me with implementing Paginated Drop-Down Combo Box using Ajax/GWT Thanks In Advance Radhika
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.