|
Posted by petersprc on 07/25/07 04:05
That will work. Instead of 'q_$i', you can use $_POST["q_$i"].
Here's an example:
<?
# survey.php
error_reporting(E_ALL);
require_once('MDB2.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$items = array();
foreach ($_POST['answers'] as $id => $answer) {
$items[] = array($id, $answer);
}
$db = MDB2::singleton('mysql://u:p@h/d');
$db->loadModule('Extended');
$st = $db->prepare('insert into answer(questionRef, answer)
values (?, ?)');
$count = $db->extended->executeMultiple($st, $items);
echo "Inserted $count answers.<br>";
}
?>
<p>Survey</p>
<form action=survey.php method=post>
Who?<br>
<input name="answers[1]"><br>
What?<br>
<input name="answers[2]"><br>
Where?<br>
<input name="answers[3]"><br><br>
<input type=submit>
<input type=hidden name=submit value=1>
</form>
On Jul 24, 3:01 pm, Miyagi <justin.michal...@gmail.com> wrote:
> I am creating a simple "or so I thought" php/mysql survey.
> There are 3 types of Surveys, with different questions. 1 for Clients,
> 1 for Employees, 1 for Peers.
> Questions for each survey are created, editable, removable, and drag/
> drop sortable.
> Options to these questions are dynamic themselves.
>
> Basically, everything works except when I try to Insert the data into
> the answers table.
>
> The one question I'm looking for is how would one process the data
> based on the respective question_id's?
> Sending it to another page would require an excessive amount of _POST
> variables, and like i said before, there are different questions for
> each survey.
>
> or would this work? (it doesn't seem to process)
> if($submit){
> for($i=$start; $i<=$end; $i++){
> $query[$i] = "INSERT INTO answer(ansresult, ansdesc, idquestion,
> idsurvey) VALUES('q_$i','exp_$i','$idquestion','$surveyType')";
> $result[$i]= mysql_query($query[$i]);
> if($result[$i]){$success++;}
>
> }
>
> $msg = sprintf("Success: %d, Questions: %d",$success,$end-$start);
> echo($msg);
>
> }
>
> Any help, advice, or direction would be greatly appreciative.
> - Justin Michaliga
Navigation:
[Reply to this message]
|