我有一个案例来编写一个测验模块,我只需要查看40个问题就可以查看它的问题。在测验之后,我必须使if ..else
条件决定哪个输入答案是真的。因为如果这是真的,我会为每个真正的答案给出一个观点。但它只是不能使它成为一个良好的条件。它可以过滤错误的答案,但不能过滤真正的答案。
我使用Yii框架,我认为它与Yii脚本没什么关系。我认为这是查询限制使它变得复杂。有人可以帮忙吗?我必须为我的最终项目完成这个。
这是我的数据库关系: “soalsoal”是问题而“jawabanjawaban”是答案。
这是我对测验表单的看法
<form method="post">
<?php
$x = 0;
foreach ($soal as $data)
{
echo $data->soal."<br>";
$list = CHtml::listData($data->jawabanjawabans, 'idjawab','jawaban');
echo CHtml::radioButtonList("jawabanku[$x]", '', $list);
$x++;
echo "<br><br><hr>";
}
?>
<div class="form-actions">
<div class="col-lg-3">
<br><br><br><br>
<button type="submit" class="btn btn-primary btn-lg" aria-label="Center">
<span class="glyphicon glyphicon-save" aria-hidden="true"></span>
Selesai
</button>
<br>
</div>
</div>
</form>
这是我的测验页面:
<div class="alert alert-dismissable alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Penting!</strong> Isikan masing-masing kolom jawaban dengan benar. <br>
Jawaban benar akan mendapat poin +4. <br>
Jawaban salah akan mendapatka poin -1. <br>
Jawaban kosong akan mendapatkan poin 0. <br>
Kerjakan dengan baik dan benar. Telitilah dalam membaca soal. Kerjakan <b>hanya soal yang yakin dapat dikerjakan</b>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title" >Simulasi</h1>
</div>
<div class="panel-body">
<?php $this->renderPartial('_form', array('soal'=>$soal)); ?>
</div>
</div>
这是我的控制器:
public function actionCreate()
{
$this->layout='//layouts/column_banksoal';
date_default_timezone_set("Asia/Bangkok");
if (isset($_POST['jawabanku']) ) {
$model=new Simulasi;
$jawabanku = $_POST['jawabanku'];
$model->idsiswa=Yii::app()->user->id;
$model->idbidang=Yii::app()->user->idbidang;
$model->date_created = date("Y-m-d H:i:s");
$jwbBenar = Soalsoal::model()->findAll(array(
"select"=>"idjawab",
"order"=>"idsoalsoal ASC"));
$benar = 0; $salah = 0; $kosong = 0; $totalskor=0; $jmlbenar=0; $jmlsalah=0;
$x = 0;
foreach ($jwbBenar as $data) {
if (!empty($jawabanku[$x])) {
if ($data == $jawabanku[$x]) {
$benar++;
} else if ($jawabanku[$x] == null) {
$kosong++;
}
$x++;
}
}
$salah = 40-($benar+$kosong);
$jmlbenar = (4*$benar);
$jmlsalah = ((-1)*$salah);
$totalskor = $jmlbenar + $jmlsalah;
var_dump($kosong,$totalskor,$jmlbenar,$jmlsalah);
$model->nilai=$totalskor;
$model->jml_benar=$benar;
$model->jml_salah=$salah;
$model->jml_kosong=$kosong;
if($model->save())
{
$id=Yii::app()->user->id;
$sql="SELECT * FROM simulasi WHERE idsiswa='$id' ORDER BY idsimulasi ASC";
$dataProvider=new CSqlDataProvider($sql,array(
'keyField' => 'idsimulasi',
));
$this->render('hasil', array(
'model'=>$model,
'benar'=>$benar,
'kosong'=>$kosong,
'salah'=>$salah,
'totalskor'=>$totalskor,
'grafikskor'=>$dataProvider,));
}
} else {
$idbidang=Yii::app()->user->idbidang;
$soal = Soalsoal::model()->findAll(array(
"select"=>"idsoalsoal,soal,idbidang,gambar,kunci,idjawab",
"condition"=>"idbidang=$idbidang",
"order"=>"rand() LIMIT 40"));
$this->render('create', array('soal'=>$soal));
}
}