Hi all.
This code creates a table with 10 random elements in it taken from a database, it also puts in 10 textareas. Each text area has a different name depending on the 'id' of the element taken from the database. The code works fine but when I press submit rather than getting a nice list of "The id for this box is 13,The id for this box is 12,The id for this box is 11 etc". I seem to get this odd behaviour where it prints
The id for this box is 13
The id for this box is 12
The id for this box is 11
The id for this box is 8
The id for this box is 6
The id for this box is 5
The id for this box is 9
The id for this box is 1
Which has randomly missed out the 4th and 6th print lines? But then if I run it again it might be the 9th and 5th prints. It only ever prints out 8 , missing two out and it never prints the full 10.
<form action="as.php" method="post">
<table width="70%" border="1">
<?php
for ( $i = 0; $i <= 9; $i += 1) {
$id = $elements[$i]->getQuestionID();
$query = "SELECT terms.id,terms.keyterm,terms.definition,terms.keywords FROM terms WHERE terms.id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$keyterm = $row['keyterm'];
print "<tr><td>KeyTerm is ".$keyterm."<br>Id is ".$id."</td><td>
<textarea name=\"$id\" cols=\"50\" rows=\"2\">The id for this box is $id</textarea>
</td></tr>";
}
// If the submit button has been pressed
if (isset($_POST['submit'])) {
for ( $j = 0; $j <= 9; $j += 1) {
$formID = $elements[$j]->getQuestionID();
//$elements[$counter]->setAnswer($_POST['$id']);
echo $_POST[$formID];
print "<br>";
}
}
?>
</table>
<input name="submit" type="submit" value="Submit">
</form>
Does anyone have an idea what is wrong with my code?
Thanks, Jake