Fill DB with values form dynamic forms
Posted: Sun Apr 29, 2007 7:21 am
Hi!
I've already posted about 2 weeks ago for a problem concerning dynamic forms.
Now I have another problem.
I create a query for teacher. First you have to pick a coursename from a list.
Then you get the names from this course and a dynamic form with those names is created:
And now I like to write the results back in the DB:
The big problem is that I don't manage to get the values ($key) to the according names. The names are only created when $i==1 because I only need them once.
In the DB it should look like this:
Lehrender / Frage1 / Frage2 / Frage3
Name1 / 1 / 3 / 2
Name2 / 2 / 5 / 6
Name3 / 3 / 4 / 1
I hope that my problem is understandable, maybe somebody could help me with this...
I've already posted about 2 weeks ago for a problem concerning dynamic forms.
Now I have another problem.
I create a query for teacher. First you have to pick a coursename from a list.
Then you get the names from this course and a dynamic form with those names is created:
Code: Select all
while($row = mysql_fetch_array($ergebnis))
{
$rname = $row[0];
echo "$rname
<table>
<tr><td>Frage1</td>
<td><input type=\"radio\" name=\"Frage1[{$rname}]\" value=\"1\"></td>
<td><input type=\"radio\" name=\"Frage1[{$rname}]\" value=\"2\"></td>
<td><input type=\"radio\" name=\"Frage1[{$rname}]\" value=\"3\"></td>
</tr>
<tr><td>Frage2</td>
<td><input type=\"radio\" name=\"Frage2[{$rname}]\" value=\"1\"></td>
<td><input type=\"radio\" name=\"Frage2[{$rname}]\" value=\"2\"></td>
<td><input type=\"radio\" name=\"Frage2[{$rname}]\" value=\"3\"></td>
</table>Code: Select all
for ($i=0; $i<3; $i++ ) {
$f = "Frage".$i;
$array[$f] = $_POST[$f];
foreach ($array[$f] as $key => $element) {
echo "In '".$key."' steht '".$element."'<br />\n";
if ($i==1){
$Lehrender = $key;
$f = $element;
$query = "INSERT INTO bewertung (Lehrender) VALUES ('$key')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
}
// select and INSERT???
}
}
mysql_close();In the DB it should look like this:
Lehrender / Frage1 / Frage2 / Frage3
Name1 / 1 / 3 / 2
Name2 / 2 / 5 / 6
Name3 / 3 / 4 / 1
I hope that my problem is understandable, maybe somebody could help me with this...