Well that fixed the error from coming up, but now the values in the db are empty. I don't even get "Array".
alex hogan > -----Original Message----- > From: Andre Cerqueira [mailto:[EMAIL PROTECTED] > Sent: Wednesday, March 03, 2004 9:34 AM > To: [EMAIL PROTECTED] > Subject: [PHP] Re: Loop Oops.... > > probably, some of those $_SESSION['question#'] are unset, or arent > arrays.. > > try: > > foreach ($answers as $questions) { > $question .= "__"; > > if (!is_array($questions)) > continue; > foreach ($questions as $subquestion) > $question .= $subquestion."--"; > } > } > > > >$insert_query = "INSERT INTO SurveyTable > > (sur_ques_id, sur_ans, sur_num) > > VALUES (1, '$questions', 1)"; > > > > $result = MSSQL_QUERY($insert_query) or die("Can not execute query > > $insert_query. "); > > > > The value in the db is either "Array" or part of the string but not > > the whole string. I know the error is creating most of the problem. > > you can only concatenate string with scalars (actually only strings, but > php do some conversions...) > if $questions is an array, you cant do that, and if its a string, you > cant foreach it > didnt you mean *VALUES (1, '$question', 1)"; ? > > > maybe im missing something... but i hope this helps > > > > Alex Hogan wrote: > > > Hi All, > > > > > > > > I am having trouble with a nested loop and I can't seem to get it > figured > > out. > > > > > > > > I keep getting an error that states, Invalid argument on line 20. > > > > > > > > Here is the code; > > > > > > > > Sessions capture question answers that are multiple answers for each > > question. > > > > $answers = > > > array($_SESSION['question1'],$_SESSION['question2'],$_SESSION['question3'] > ,$ > > _SESSION['question4'], > > > > > > > $_SESSION['question6'],$_SESSION['question7'],$_SESSION['question8'],$_SES > SI > > ON['question9'], > > > > > $_SESSION['question10'],$_SESSION['question11']); > > > > > > > > I init the vars > > > > $question = ""; > > > > $subquestion = ""; > > > > > > > > Here's the loop I'm having trouble with. > > > > foreach ($answers as $questions) { > > $question .= "__"; > > foreach ($questions as $subquestion) { -- Here's the offending line > -- > > $question .= $subquestion."--"; > > } > > } > > > > > > > > I am inserting an array of arrays..., I know it's not the best way to do > > this but I was only given a few hours to get this up. > > > > The array is delimited by a double underscore and individual answers are > > delimited by a double hyphen. Or at lease that's what's supposed to > happen. > > > > > > > > $insert_query = "INSERT INTO SurveyTable > > > > (sur_ques_id, sur_ans, sur_num) > > > > VALUES (1, '$questions', 1)"; > > > > $result = MSSQL_QUERY($insert_query) or die("Can not execute query > > $insert_query. "); > > > > > > > > The value in the db is either "Array" or part of the string but not the > > whole string. I know the error is creating most of the problem. > > > > > > > > I can't see what I'm doing wrong.... Why is that argument invalid? > > > > > > > > alex hogan > > > > > > > > > > > > ****************************************************************** > > The contents of this e-mail and any files transmitted with it are > > confidential and intended solely for the use of the individual or > > entity to whom it is addressed. The views stated herein do not > > necessarily represent the view of the company. If you are not the > > intended recipient of this e-mail you may not copy, forward, > > disclose, or otherwise use it or any part of it in any form > > whatsoever. If you have received this e-mail in error please > > e-mail the sender. > > ****************************************************************** > > > > > > > > -- > André Cerqueira ****************************************************************** The contents of this e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. The views stated herein do not necessarily represent the view of the company. If you are not the intended recipient of this e-mail you may not copy, forward, disclose, or otherwise use it or any part of it in any form whatsoever. If you have received this e-mail in error please e-mail the sender. ******************************************************************