RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2804 | Replies: 1 | Thread Tools  Display Modes
Reply
Join Date: Jul 2007
Posts: 3
Reputation: concordia is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
concordia concordia is offline Offline
Newbie Poster

Creating a multi-dimensional Session variable

  #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.

//items is the checkbox
//$curr is a string created designating the question
$answers = $_POST['items'];
if (count($answers) > 0)
{	
	$_SESSION['answers'][$curr]=$answers;	

	print_r($_SESSION['answers']);
}

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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Washington State
Posts: 53
Reputation: SStedman is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
SStedman SStedman is offline Offline
Junior Poster in Training

Re: Creating a multi-dimensional Session variable

  #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
Please
Visit My Website
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:37 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC