MVC increment score if answer is correct

Hello

I am trying to develop a simple MVC quiz application. At the moment the application is ok by displaying if the user answer correctly or not.
Now I am trying to write code that would count how many answers the user answered correctly.
I have a general idea how I can achieve this but can’t seem to put the code together to work.
My idea is:
In the view the user should see how many questions he answered correctly.
When answering the controller pulls the data from the view calls the function from the model and sends the data back to the view with the relevant message.
At the same time when the controller checks if the answer is correct I am trying to pull the current correctly answered value from the view,(let’s say at the beginning is 0)If the function that checks if the answer is correct returns true, then call the function to increment the user score from the model.
The controller gets the result and sends it back to the view.
Here is some sample code:

//Code for the view. Hidden field that should store the score
<input type=hidden name=count>
//display the score to the user
<div> <?php echo $increment ?> </div>	

//Controller: trying to get value of the field with the current score
$c = $this->input->get('count', false);
//Controller: Passing to the function "increment" the bolean if the answer si correct or not, and the current score of the user ("c").
$counter = $this->Starmodel->increment($res, $c);

//function in model: if answer correctlly, add to the current counter and return.
function increment($res, $counter){
	if($res){
		$counter = $counter + 1;
		return counter;
	}
}

Would really appreciate some help on this. Also I might be doing it wrong, so I am open for suggestions. Thanks.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.