Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Rotating Through Alphabetical List - In Order

Community Beginner ,
Apr 29, 2008 Apr 29, 2008
Maybe I haven't had enough coffee or I'm just tired from getting up in the middle of the night for my 1 year old, teething daughter, but I just can't seem to think of a simple way to rotate through a list in order. Here's what I'm trying to do... I have an alphabetical list of companies displayed on my site (advertisers). The companies at the bottom of the list are getting annoyed that they're always at the bottom. So, I want to make the list of companies start at a new position each time (in order). So, it would start outputting in this order: a-z, then coufput "b-z" / cfoutput "a" (two cfoutputs), then "c-z" / "a-b", etc.. But, I don't want it to start at a-z for each new visitor to the page, I want it to remember the last display, say d-z / a-c and start with e-z for the next visitor.

One of my ideas relate to saving a variable in the database each time the page is viewed and doing a plus one to figure out the starting position. And, when it gets to the total number of records in the list starting back to 1. Isn't that too complicated. What am I forgetting?

Hopefully, someone can help me. Maybe I'll go get another cup of coffee and see if that helps....
244
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 29, 2008 Apr 29, 2008
LATEST
Assuming your list of names comes from a db, there is another approach. If your db supports it, get the minimum length of the company name (trimmed of course) each time you run the query. Then generate a random number between 1 and that value. Let's call it n. Sort your query by the nth character. That should make it different each time.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources