[Help] Make Online Exams

Hai guys, i want to make online exams aplication like this,

5437

exam.jpg

and my script is

Controller




public function actionQuestion(){

	$this->render('question');

}



view




<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>


<script>

var totaltime = 20;  //time limit to do the exam

var indexquestion = 0;

var category;

var timer;

var timeup = 0;

var finalvalue = 0;

$(document).ready(function(){

    $("#benar").val(finalvalue);

    category = $("#divcategory").html();

    url = "getquestion"

    $.ajax({

        url: url,

        dataType: 'json',

        cache: false,

        success: function(msg){

            category = msg;

            showquestion();

           settime();

        }

    });

    $("#next").click(function(){

        indexquestion++;

        $("#divperquestion").hide();

        $("#divoption").hide();

        showquestion();

    });

});


function setvalue(value){

    idinput = "#choose"+indexquestion;

    $(idinput).val(value);

}


function settime(){

    if(totaltime>0){

        $("#divtotaltime").html(totaltime);

        totaltime--;

        timer = setTimeout("settime()",1000);

    }else{

        clearTimeout(timer);

        timeup = 1;

        document.getElementById("formulir").submit();

    }

}


function showquestion(){

    if(indexquestion<category.question.length){

        numberquestion = indexquestion + 1;

        $("#divnumber").html("Question "+numberquestion+" from "+ category.question.length);

        $("#divperquestion").html(category.question[indexquestion].pertanyaan);

        $("#divperquestion").fadeIn(2000);

        $("#answer_a").html("<input type='radio' onclick='setvalue(this.value)' name='R"+indexquestion+"'value='a'>A. "+category.question[indexquestion].a);

        $("#answer_b").html("<input type='radio' onclick='setvalue(this.value)' name='R"+indexquestion+"'value='b'>B. "+category.question[indexquestion].<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />;

        $("#answer_c").html("<input type='radio' onclick='setvalue(this.value)' name='R"+indexquestion+"'value='c'>C. "+category.question[indexquestion].c);

        $("#answer_d").html("<input type='radio' onclick='setvalue(this.value)' name='R"+indexquestion+"'value='d'>D. "+category.question[indexquestion].d);

        $("#divoption").slideDown(750);

    }else{

        timeup = 1;

        document.getElementById("formulir").submit();

    }

}

</script>


<style>

body{font-family:arial}

#divperquestion{padding:10;background-color:yellow;display:none}

#divoption{padding:10;background-color:pink;display:none}

</style>

</head>


<h2 class=time>Time to do the exam : <span id="divtotaltime"></span></h2>

<div id="divnumber"></div>

<b><div id="divperquestion"></div></b>

<div id="divoption">

<span id="answer_a"></span><br>

<span id="answer_b"></span><br>

<span id="answer_c"></span><br>

<span id="answer_d"></span>

</div>

<p>

<div id="divchoose"></div>



Controller




public function actionGetquestion(){

$topik = 'internet';

$data = mysql_query("SELECT * FROM banksoal WHERE topik='$topik'");

$sql = "SELECT * FROM banksoal WHERE topik=:topik";

$topik="internet";

$command = Yii::app()->db->createCommand($sql);

$command->bindParam("topik", $topik, PDO::PARAM_INT);

$rows = $command->query();	


$json = '{"question":[ ';

while(($x = $rows->read())!==false){

    $json .= '{';

    $json .= '"id":"'.$x['soalid'].'",

        "topik":"'.htmlspecialchars($x['topik']).'",

        "pertanyaan":"'.htmlspecialchars($x['pertanyaan']).'",

        "a":"'.$x['pilihan_a'].'",

        "b":"'.$x['pilihan_b'].'",

        "c":"'.$x['pilihan_c'].'",

        "d":"'.$x['pilihan_d'].'",

        "jawaban":"'.$x['jawaban'].'"

    },';

}

$json = substr($json,0,strlen($json)-1);

$json .= ']';

$json .= '}';

echo $json;	

$this->render('getquestion');	

}



but nothing display 5438

yiiexam.jpg

i have no idea which part in wrong with my code, can somebody show me how to fix this

cause this really important for me…

Thx…Regards

Unsolved :(

May not be the only problem, but I think the bindParam is wrong:


$command->bindParam(":topik", $topik, PDO::PARAM_INT);

I think you need the ‘:’ in there somewhere.