PHP编写在线考试题,急需高手指教!谢谢!
现在数据库有了,要用rand乱数随机生成数据库里的试题,还得有採分设置,现在很乱!<?phprequire ('dbconnect.php');// データベース接続:
if (!empty($_POST)) {
$yougo = mysql_real_escape_string($_POST['yougo']);
$query = "SELECT * FROM yougosyu WHERE yougo like '$yougo%'";
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
// step 1
$count = 1;
while ($row = mysql_fetch_assoc($result)) {
$count++;
}
//step2
$ran = mt_rand();
$bingo = $ran % $count + 1;
$result = mysql_query($query);
$count = 1;
while ($row = mysql_fetch_assoc($result)) {
$count++;
if ($count == $bingo){
echo $count;
echo ') ';
echo $row['yougo'];
echo '...';
echo $row['setumei'];
}
}
$ran = mt_rand();
$pos = $ran % 4 + 1;
echo $pos;
mysql_free_result($result);
}
?>
<form action="./yougo_query.php" method="post">
<font size=3>
<dl>
用語検索 <input type="text" name="yougo" />
</dl>
<input type="submit" value="検索" />
<a href="./index.html">Top Page へ</a>
</form>