Creating a multi-dimensional Session variable

Reply

Join Date: Jul 2007
Posts: 3
Reputation: concordia is an unknown quantity at this point 
Solved Threads: 0
concordia concordia is offline Offline
Newbie Poster

Creating a multi-dimensional Session variable

 
0
  #1
Jul 18th, 2007
Hi again,

I'm stumped. I'd like to store results from a questionnaire in a multi-dimensional session variable to tally the number of questions answered after the entire questionnaire is completed. Users choose selections from checkboxes, so I have that info coming from an array. I was hoping I could just create an array of answers, keyed by the question, but I'm having some issues. Here is a code snippet.

  1. //items is the checkbox
  2. //$curr is a string created designating the question
  3. $answers = $_POST['items'];
  4. if (count($answers) > 0)
  5. {
  6. $_SESSION['answers'][$curr]=$answers;
  7.  
  8. print_r($_SESSION['answers']);
  9. }

When I print out the contents of the array, it gives me:
Array ( [0] => 31 [1] => 32 [2-2] => Array ( [0] => 31 [1] => 32 [2-2] => Array *RECURSION* ) )

I feel like it should be:
Array( [2-2] => Array ( [0] => 31 [1] => 32 )
At least that's what I want to happen. I also only have one php page and depending on what's passed into the url, different questions are shown. Because of this, it seems like my answers array isn't adding the new arrays.

Weird thing is when I hardcoded everything, this worked just fine. Now that I want it more dynamic, it isn't working. Any ideas? Or maybe there's some other way I'm not seeing. TIA!
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 54
Reputation: SStedman is an unknown quantity at this point 
Solved Threads: 0
SStedman SStedman is offline Offline
Junior Poster in Training

Re: Creating a multi-dimensional Session variable

 
0
  #2
Jul 18th, 2007
Try the
print_r($_SESSION['answers']);
before you set to see how it looks.

This might help with the debugging.
Steve Stedman - Software Development Professional
Questions about anything?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC