By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

a weighted order by rand()?

P: n/a
I am managing banners visualization using a php/mysql script.

Currently, the banner is extracted from a table using a "select * from
banners order by rand limit 1" query.

Anyway this is a completely random extraction. I would like to
introduce a weight in order to have some banner extracted more
frequently. Is there any way to do this (note that I can not modify the
table adding more times the same banners).

M.
--
http://incuso.altervista.org

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
*** nu*********@gmail.com wrote/escribió (15 May 2005 05:55:33 -0700):
I am managing banners visualization using a php/mysql script. [...] Anyway this is a completely random extraction. I would like to
introduce a weight in order to have some banner extracted more
frequently. Is there any way to do this (note that I can not modify the
table adding more times the same banners).


I haven't done the math to calculate probabilities but...

select rand()*weight as random_position
from banners
order by random_position desc
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.