RE: [PHP] Re: Pulling a random image
| From: | Brad R. C. | Date: | Mon, 03 Sep 2001 20:08:44 +0000 |
| Subject: | RE: [PHP] Re: Pulling a random image | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-65789@lists.php.net to get a copy of this message | ||
You know what.. that might just work the way I need it to... will try it out
tonight, thanks!!! :)
Brad C.
-----Original Message-----
From: Hugh Bothwell [mailto:hugh_bothwell@hotmail.com]
Sent: Monday, September 03, 2001 1:05 PM
To: php-general@lists.php.net
Subject: [PHP] Re: Pulling a random image
"Brad R. C." <bradc@addictedusers.com> wrote in message
news:ELEKJPELJEFCJONHNNAOMEBCCJAA.bradc@addictedusers.com...
> But what my goal was is to make it where it goes through all the images
> before showing a random twice.
... if you actually want to do this, you will have to keep track
of which items you have seen in the last rotation.
> Now... I thought the following function did that, but for some reason it
is
> not...
Nope. You are just (inefficiently) choosing one item at random.
An equivalent-but-faster approach would be
SELECT * FROM user
WHERE valid=1 AND inrotation=1
ORDER BY RAND() LIMIT 1
If you really need random-order, once-per-cycle images,
you could achieve it by adding a 'views' field to the table;
initialize all entries to the same value (ie 0). Each time an image
is displayed, increment the views; when you choose an image,
choose from the pool where the views value is minimal, ie.
SELECT id,imgname FROM user
WHERE valid=1 AND inrotation=1 AND views=MIN(views)
ORDER BY RAND() LIMIT 1
UPDATE user SET views=views+1
WHERE id=$id
How's that?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net