Re: How do I produce a random database query for each day or week?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



My idea on your problem would be to use a random sql-query selecting a
cd from your database.

SELECT * FROM my_table ORDER BY RAND() LIMIT 1;

This could be placed in a script that is executed only by the first
user in a week and the result is stored e.g. in a text file and
included in any later call of your website. It's too early in the
morning for details (I just stood up), but if you have questions about
realization please ask.

Dirk.


On Fri, 01 Oct 2004 15:45:54 +0200, -{ Rene Brehmer }-
<metalbunny@xxxxxxxxxxxxxx> wrote:
> At 10:31 01-10-2004, Graham Cossey wrote:
> >A couple of thoughts:
> >
> >As you want to cycle through the list rather than randomly (with repetition)
> >picking from the list, have you considered storing the last CD shown details
> >in the DB?
> >
> >If each CD has a sequential ID then each week (or day) you increment the
> >number which will determine what CD is shown. If the incremented CD id
> >exceeds the highest id in the DB, restart back at the first id.
> 
> Just incrementing the ID is not a good idea. It does not allow for the
> flexibility required if you suddenly delete a CD in the middle. So it'd be
> better doing something like "SELECT * FROM cds WHERE `CDid`>'$LastCDid' ".
> Then obviously you'd need to check if the last shown was the last in the
> base, you'd get 0 rows. But this can be circumvented by just checking the
> number of rows returned, and if the rowcount is < 1, simply do a new SELECT
> with CDid > 0.
> 
> >You could also include a column (or two) in the CD info table to record when
> >it was last displayed and check that this is > 29 days ago.
> 
> I agree that this would be the easiest way. On every display you do an
> update to store the date, then on each page load just calculate how long
> ago the CD show must've been shown last.
> 
> >What about cookies? Each visitor could then have their own 'cycle' through
> >the list.
> 
> This is a per need basis. With the "last shown date" you don't need the
> cookies.
> 
> --
> Rene Brehmer
> aka Metalbunny
> 
> If your life was a dream, would you wake up from a nightmare, dripping of
> sweat, hoping it was over? Or would you wake up happy and pleased, ready to
> take on the day with a smile?
> 
> http://metalbunny.net/
> References, tools, and other useful stuff...
> Check out the new Metalbunny forums at http://forums.metalbunny.net/
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 



-- 
Try http://einx.dyndns.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux