限制用户添加记录(如果已存在)

时间:2014-11-21 15:09:28

标签: php mysql

我正在研究电子考试系统。我正在使用的结构是每个测试有很多问题所以我想做什么

如果已经为所选测试创建了问题,

会限制用户添加问题。

$request=$_REQUEST['manageqn'];

//从问题表

获得结果
$select=$connection->query("SELECT count(*) as q FROM questions where related_to_test='$rl'");
$r1=$select->fetch_assoc();     
//This get results from test table
$select2=$connection->query("SELECT * FROM test where test_id='$rl'");
$r2=$select2->fetch_assoc();

//即使条件为真,此代码也不会执行

if ((int) $r1['q'] === (int) $r2['total_quesiton']){
echo "All the Questions are Created for this test $rl ".$r2['test_name'];
}else{

//每次都运行此代码

echo "<div class=\"alert alert-success\">Test Name: " .$r2['test_name'] . "<br/>Status: Still you need to create " 
. ($r2['total_question'] - $r1['q']) . " Question/s. After that only, test will be available for candidates.</div>";
}  

0 个答案:

没有答案