can’t solve it working !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
« Home
Pages
-
Categories
-
Archives
can’t solve it working !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$GLOBALS['choice'] = array(0 => $opt1[0], 1 => $opt2[0], 2 => $opt3[0], 3 => $ans[0]);
$GLOBALS['num'] = range(0,3);
srand((float)microtime() * 1000000);
shuffle($GLOBALS['num']);
echo "<p style='color:rgb(1,255,1);'>以下那一個是錯別字:</p>";
for ($i = 0; $i <= 3; $i++) {
echo $i+1 . ": " . $GLOBALS['choice'][$GLOBALS['num'][$i]] . " ";
// to capture the answer number (for MC of four options)
if ($GLOBALS['num'][$i] == 3) $GLOBALS['ansnum'] = $i;
}
A little technical problem:
PHP part:
<select id="mc"> <option value="1"><?php echo $choice[0];?></option> <option value="2"><?php echo $choice[1];?></option> <option value="3"><?php echo $choice[2];?></option> <option value="4"><?php echo $choice[3];?></option> </select> <input type="button" id="answer_btn" style="float: left;" value="選擇答案" onclick="answerbox(<?php echo $ans[0];?>)"/>
jScript part:
function answerbox(a) {
obja = document.getElementById("mc");
if (a == obja.value)
alert ("correct !");
else
alert ("wrong !");
}
CAN’T GET IT OUT !!!!!!!!!!!!!!!!!!!!!
$query = "SELECT cword FROM ww_tbl ORDER by rand() LIMIT 1";
$result = mysql_query($query);
$opt1 = mysql_fetch_row($result);
$query = "SELECT cword FROM ww_tbl ORDER by rand() LIMIT 1";
$result = mysql_query($query);
$opt2 = mysql_fetch_row($result);
$query = "SELECT cword FROM ww_tbl ORDER by rand() LIMIT 1";
$result = mysql_query($query);
$opt3 = mysql_fetch_row($result);
$query = "SELECT wword FROM ww_tbl ORDER by rand() LIMIT 1";
$result = mysql_query($query);
$ans = mysql_fetch_row($result);
$choice = array(0 => $opt1[0], 1 => $opt2[0], 2 => $opt3[0], 3 => $ans[0]);
$num = range(0,3);
srand((float)microtime() * 1000000);
shuffle($num);
echo "<p style='color:rgb(1,255,1);'>以下那一個是錯別字:</p>";
foreach ($num as $n) {
echo $choice[$n] . " ";
}
$query = "SELECT wword ,cword FROM ww_tbl ORDER by rand() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_row($result); echo $row[0] . "的正寫應是" . $row[1] ;