Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.