Skip to main content
Participant
April 29, 2008
Question

Rotating Through Alphabetical List - In Order

  • April 29, 2008
  • 1 reply
  • 264 views
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....
    This topic has been closed for replies.

    1 reply

    Inspiring
    April 29, 2008
    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.