473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

a weighted order by rand()?

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
1 1851
*** 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jefferis NoSpamme | last post by:
I have a query that is showing new items in a store based upon their inventory date. The problem with my Random order sort is that when the "next" link is pressed, the random function is called...
2
by: Joe Blower | last post by:
When I execute the following SQL statement at the mysql> prompt, I get a random result: SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT 1; When I wrap it in my perl code, I...
6
by: Alkaline | last post by:
Ok, how to do this efficiently escapes me, so I'm going to ask and see if anyone might have ideas. My problem is really simple. I have a database filed with user comments. It's basic fields are...
2
by: Louis | last post by:
Hi, Does anyone know of a script that will give "weighted job duration"? I want to use it, to identify which jobs are hogging the CPU. That is for a given server, list the sql agent jobs...
22
by: Nhmiller | last post by:
Is there a way to do this? Thanks. Neil Cat Paintings At Carol Wilson Gallery http://www.carolwilsongallery.com
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
2
by: yay_frogs | last post by:
Here is my problem: suppose there are, say, five events with these probabilities: event1 0.7 event2 0.1 event3 0.1 event4 0.05 event5 0.05 Note that sum of the probabilities is...
3
by: Salad | last post by:
http://www.mathwords.com/w/weighted_average.htm At the above link gives an example of a weighted average. It uses the following example: Grades are often computed using a weighted average....
0
by: edmund_xue | last post by:
Hello There, I was just working on a project of creating a database for a relative that have alots of clients. His company managed the shares portfolio of clients and he requires the buy price...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.