Jump to content

multidimensional arrays?


grantypap

Recommended Posts

hey guys,

 

i have a form for a php/mysql based online test.

 

at present the code calls the questions and their unique ID's and puts the questions in a table and adds the ID as a hidden field.

the problem that i am having is that im not sure how i am going to put the answers back in the DB.

 

i cant just use the POST method because there may be hundreds of entry's so i was thinking of using 2 arrays, 1 for ID's and 1 for questions.

ie. the first entry in ID_array will match the first entry in QUESTION_array.

 

this would work fine but for some questions there can be more than one possible answer.

do you think that multidimensional arrays may be the way to go?

if so how would you suggest i implement this?

 

Cheers,

Grant

Link to comment
Share on other sites

personally... i'd run it like this...

 

$array[1][question]='question';
$array[1][answer][]='answer1';
$array[1][answer][]='answer2';

 

then when you take em out... just foreach($array[1][answer] as $val)

Link to comment
Share on other sites

how would i get the answers in their though?

 

once the user has completed the test and hit submit would i still need grab their input and try and match it up with that array (on the script page)?

i guess that everything needs to happen on the form because by the time it gets to the script it will all be out of order?

 

im really stumped on this one!!

 

cheers,

Grant

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.