random
Posted: Thu Sep 04, 2003 9:49 am
hi guys, ive a question
im trying to made a script with rand, but the priority in the rand is important. I explain myself more:
ive a selectbox with prioriter from 0 to 9 10 is the smallest priority, and 10 is the biggest priority.
in my case, 10 has 10 more chance of being choose then the 1.
this is how ive started:
<?php
$pri = rand(0,10);
$max = 0;
while ($max == 0) {
//$max = "SELECT COUNT(table_id)
FROM table_name
WHERE priority=$pri";
}
$choose = rand(0,$max);
$db_query = "SELECT *
FROM table_name
LIMIT $choose,1";
but with this code, 1 has the same chance of being choose then the 10, and id like respect the priority.
if someone can help me, it would be really appreciated. and without case (if possible).
thanks
im trying to made a script with rand, but the priority in the rand is important. I explain myself more:
ive a selectbox with prioriter from 0 to 9 10 is the smallest priority, and 10 is the biggest priority.
in my case, 10 has 10 more chance of being choose then the 1.
this is how ive started:
<?php
$pri = rand(0,10);
$max = 0;
while ($max == 0) {
//$max = "SELECT COUNT(table_id)
FROM table_name
WHERE priority=$pri";
}
$choose = rand(0,$max);
$db_query = "SELECT *
FROM table_name
LIMIT $choose,1";
but with this code, 1 has the same chance of being choose then the 10, and id like respect the priority.
if someone can help me, it would be really appreciated. and without case (if possible).
thanks