Form Submission array handling
Posted: Mon Mar 16, 2009 11:03 am
I have a form that is a survey which has a variable number of questions in it. There are two types of question in it, rating questions (under which a variable number of people are rated) and text questions.
So for each rating question I need to insert into a table called FeedbackRating
FeedbackID
QuestionID passed through as RQuest (and then an incrementing number on the end)
LecturerID passed through as LecsID (" same as above, eg first will be LecsID1, LecsID2...)
RatingValue passed through as Rat (" same as above Rat1, Rat2, Rat3)
What this does is cycle through all the Rat posts and inserts them all fine. However I can't work how how to expand this to do the RQuest and LecsID.
I thought it might be something like this however it doesn't work
Hope I have explained this well enough anyway. Any thoughts would be great.
As a side note QuestionID and LecturerID are numerical and RatingValue can either be text or numerical
Thank you
So for each rating question I need to insert into a table called FeedbackRating
FeedbackID
QuestionID passed through as RQuest (and then an incrementing number on the end)
LecturerID passed through as LecsID (" same as above, eg first will be LecsID1, LecsID2...)
RatingValue passed through as Rat (" same as above Rat1, Rat2, Rat3)
Code: Select all
<?php
$FeedbackID = mysql_insert_id();  # fetch the newly generated id
$RatingQuests = array();
for($i=1;$i<=40;$i++)  # create array with 1-40 elements
if(isset($_POST['Rat'.$i]) and ($_POST['Rat'.$i] > ""))
$RatingQuests[] = '('.$FeedbackID.',"'.($_POST['Rat'.$i]).'")';
$values = implode(',',$RatingQuests);
$sql2 = "INSERT INTO FeedbackRating (FeedbackID,RatingValue) VALUES $values";
?>I thought it might be something like this however it doesn't work
Code: Select all
<?php
$FeedbackID = mysql_insert_id();  # fetch the newly generated id
$RatingQuests = array();
for($i=1;$i<=40;$i++)  # create array with 1-40 elements
if(isset($_POST['RQuest'.$i]) and ($_POST['RQuest'.$i] > "")) && isset($_POST['LecsID'.$i]) and ($_POST['LecsID'.$i] > "")) && isset($_POST['Rat'.$i]) and ($_POST['Rat'.$i] > "")))
$RatingQuests[] = '('.$FeedbackID.',"'.($_POST['RQuest'.$i]).'","'.($_POST['LecsID'.$i]).'","'.($_POST['Rat'.$i]).'")';
$values = implode(',',$RatingQuests);
$sql2 = "INSERT INTO FeedbackRating (FeedbackID,QuestionID,LecturerID,RatingValue) VALUES $values";
?>
As a side note QuestionID and LecturerID are numerical and RatingValue can either be text or numerical
Thank you