I found this function at php.net under the quick reference from a visitor:
function randomrec($table, &$row, $db)
{
$sql = "SELECT FROM $table";
$result = mysql_query($sql, $db);
$numrecs = mysql_num_rows($result);
srand((double)microtime()1000000);
$recnum = rand(0, $numrecs-1);
$sql = "SELECT * FROM $table LIMIT $recnum, 1";
$result = mysql_query($sql, $db);
$row = mysql_fetch_array($result);
}
I've got a dilemna that the above posted solution won't solve. I've got a table, with some rows marked as "active" and others as "in-active".
I want to randomly select an ACTIVE row.
Above methods people have posted do not do this. They assume that all rows can be chosen.
To further complicate matters, I'd like to add a column that specifies a "probability to be chosen" (for example range 1-5). Basically I want some rows to have a higher probability to be chosen than others.
I've been wrapping my brain around this for days with no luck..can anyone help?