<?
# quizmysql version 1.0 with mysql
# this program have [quiz] table in [test] database
# mysql> create table quiz(qid int,ques char(50),c1 char(50),c2 char(50),c3 char(50),c4 char(50),ans int);
# mysql> insert into quiz values(1,'1+1','2','3','4','5',1);
# mysql> insert into quiz values(2,'5+6','7','9','11','13',3);
# mysql> insert into quiz values(3,'ant','boy','girl','cat','man',3);
#######################################
$host = "localhost";
$db = "test";
$tb = "quiz";
$user = "root";
$password = "yourpassword";
$query = "select * from $tb";
$connect = mysql_connect("$host","$user","$password");
$result = mysql_db_query($db,$query);
if ($result) echo "<b>Quiz</b>"; else exit;
$right = "<br><input type=radio onclick=alert('right')>";
$wrong = "<br><input type=radio onclick=alert('wrong')>";
while ($object = mysql_fetch_object($result)) {
echo "<br><b>".$object->qid." : ".$object->ques."</b>";
if ($object->ans == 1) echo $right; else echo $wrong; echo $object->c1;
if ($object->ans == 2) echo $right; else echo $wrong; echo $object->c2;
if ($object->ans == 3) echo $right; else echo $wrong; echo $object->c3;
if ($object->ans == 4) echo $right; else echo $wrong; echo $object->c4;
}
mysql_close($connect);
?>
จำนวน : 28 บรรทัด