Problem in searching through a 2D array - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problem in searching through a 2D array

adeydasadeydas Posts: 43Member
Hi,

I am trying to make an online examination script in PHP and am stuck at the results page.
The actual answers here are stored in a 2D array called 'ans' in the format:

Say for question 1 the answers are options 2 and 4, then it would be stored as

12 14

If for the second question the answers are option 1 ,3 and 4 then

21 23 24

So the whole array would look like:

12 14
21 23 24

The options are check boxes with ID's and names similar to the way it is stored in the array.

I am using the following snippet of code to check through the answers:
Code:

[code]$tot=0;
$cq=0;
for($i=1; $i<=$noq2d; $i++)
{
$nomore=false;
$rt=false;
for($j=1; $j<7; $j++)
{
$z=$i.$j;

if($_POST[$z] && $nomore==false && in_array($z,$ans[$i]))
{
$rt=true;
}
else
{
$rt=false;
$nomore=true;
}
}

if($rt==true)
{
$tot=$tot+$mpq;
$cq++;
}
}

echo('Total: '.$tot.'<br>
');
echo('Number of correct answers: '.$cq);
[/code]

However, it is giving 0 as the result under any and every situation. The full code of the result page is here: http://adeydas.com/dump/result.phps

Any help will be highly appreciated!

Thanks.

Abhishek
http://adeydas.com
Sign In or Register to comment.