[PHP-DB] Re: Random

2002-08-11 Thread David Robley

In article 003601c241ad$225775e0$[EMAIL PROTECTED], 
[EMAIL PROTECTED] says...
 can someone help me to generate a random records from the database?
 eg,
 
 rec 1 john doe
 rec 2 jay williams
 rec 3 anie boo
 
 random results:
 
 rec 2 jay williams
 rec 1 john doe
 rec 3 anie boo
 
 .

Check your database documentation - at least Mysql has a RANDOM function.

-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Re: Random

2002-08-11 Thread Russ

ORDER BY RAND()

Russ

-Original Message-
From: David Robley [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 12, 2002 1:08 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: Random


In article 003601c241ad$225775e0$[EMAIL PROTECTED], 
[EMAIL PROTECTED] says...
 can someone help me to generate a random records from the database?
 eg,
 
 rec 1 john doe
 rec 2 jay williams
 rec 3 anie boo
 
 random results:
 
 rec 2 jay williams
 rec 1 john doe
 rec 3 anie boo
 
 .

Check your database documentation - at least Mysql has a RANDOM
function.

-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] Re: Random question selection in PHP w/ MySQL backend.

2001-07-31 Thread Hugh Bothwell


 Adam Lundrigan [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 What i need to do is select 10 questions from a database
 (db: vpt, table: questions), and make sure that the same
 question doesn't appear twice. The questions need to
 appear in a random order each time the script is loaded.

$mysql_connect(host, user, pwd);

$result = $mysql_db_query(vpt,
SELECT id, txt FROM questions 
.ORDER BY RANDOM() LIMIT 10
);

function makeQuestion($qid) {
return (
 input type='radio' name='q[$qid]' value=11
.input type='radio' name='q[$qid]' value=22
.input type='radio' name='q[$qid]' value=33
.input type='radio' name='q[$qid]' value=44
.input type='radio' name='q[$qid]' value=55
);
}

function makeRow() {
$str = \n\ttr;

$num = func_num_args();
for ($i = 0; $i  $num; $i++)
$str .= \n\t\ttd.func_get_arg($i)./td;

$str .= \n\t/tr;
return $str;
}

echo \nform\ntable;

while ($row = mysql_fetch_array($result))
echo makeRow(makeQuestion($row[id]), $row[txt]);

echo makeRow(input type='reset', input type='submit');
echo \n/table\n/form;



Voila - they get ten questions at random, in random order;
 when they submit the form, you get the question id back as
the array key and the answer as the value.

Hope that helps ;-)



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]