PHP mysql Online exam system

Source: Internet
Author: User
Tags explode mysql tutorial php mysql php tutorial

A simple PHP tutorial MySQL tutorial exam system, the example method is to determine whether the topic array is empty, empty then from the question bank randomly removed 12 questions ID

<?php
Include './inc/header.php ';
if ($_session[' arr '] = = ') {#判断题目数组是否为空, empty then randomly take out 12 questions ID from the question bank
$sql = ' select * from ';
$select = $db->select ($sql);
for ($i =0; $i <count ($select); $i + +) {
$aid. = $select [$i] [' ID ']. ', ';
}
$arr = Explode (', ', substr ($aid, 0,strlen ($aid)-1));
Shuffle ($arr);
$_session[' arr ' = Array_slice ($arr, 0,12);
}
$array = $_session[' arr '];
if ($_server[' request_method '] = = "Post") {
if ($_session[' arr1 '] = = "") {#arr1存的是已答题的id
$ary = $array;
Array_shift ($ary); #每答完一道题后, delete the first bit of the array
$_session[' arr1 ' = $ary;
}else{
$ary = $_session[' arr1 '];
Array_shift ($ary);
$_session[' arr1 ' = $ary;
}
$id = $_post[' id '];
$answer = $_post[' answer '];
$SQQ = ' select * from ' where id= '. $id. ' answer= '. $answer. ' "
$qus = mysql_query ($SQQ);
$rows = @mysql_num_rows ($qus);
if ($rows) {
$_session[' right ']. = $id. ', '; #将答对题id存到session [' Right ']
$rightarr = Explode (', ', substr ($_session[' right '],0,strlen ($_session[' right '))-1); #判断对题数
if (count ($rightarr) <) {#如果小于10则继续答下一题
$sql 2 = ' select * from where id= '. $ary [0];
$sel = $db->select ($sql 2);
}elseif (count ($rightarr) = =) {#如果等于10则跳出此次问答
$time = time ();
$_session[' jiang ' = MD5 ($time);
#echo ' <script>location.href= ' right.php?uid= '. $time. ' "; </script> ';
$success = Array (' Second ' => ' 3 ', ' url ' => ' right.php?uid= '. $time, ' title ' => ' answer ten questions correctly ', ' right ' => ' Congratulations, you've answered 10 straight questions. , you will jump to the redemption page. ');
$smarty->assign (' msg ', $success);
$smarty->display (' success.html ');
Exit ();
}
}else{
$_session[' ERROR ']. = $id. ', '; #将答错题id存到session [' ERROR ']
$errorarr = Explode (', ', substr ($_session[' Error '],0,strlen ($_session[' ERROR ')-1)); #判断错题数
if (count ($errorarr) < 2) {
$sql 2 = ' select * from where id= '. $ary [0];
$sel = $db->select ($sql 2);
}elseif (count ($errorarr) = = 2) {#如果答错两题, then count again
unset ($_session[' right ']);
unset ($_session[' error ')];
unset ($_session[' arr1 '));
unset ($_session[' arr '));
unset ($_session[' num ']);
Session_destroy ();
#echo ' <script>location.href= ' index.php ';</script> ';
$success = Array (' Second ' => ' 3 ', ' url ' => ' index.php ', ' title ' => ' wrong two questions ', ' error ' => ' Sorry, you have two consecutive wrong answers, will be recalculated ');
$smarty->assign (' msg ', $success);
$smarty->display (' success.html ');
Exit ();
}
}
Echo ' right: '. $_session[' right '. ' <br/> ';
Echo ' ERROR: '. $_session[' error '. ' <br/> ';
}else{
$SQLL = ' select * from where id= '. $array [0];
$sel = $db->select ($SQLL);
}
if (isset ($_session[' num ')) {#目前答第几题
$num = $_session[' num '] + 1;
$_session[' num '] = $num;
#echo $_session[' num ']. ' <br/> ';
#echo $num;
}else{
$num = 1;
$_session[' num '] = $num;
}
$smarty->assign (' num ', $num);
$smarty->assign (' ob ', $sel);
$smarty->display (' index.html ');

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.