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]