I have a page that displays a table where the rows in the table are generated from a database. The table contains 10 questions as below
When this is filled in it saves to another table in the database.
What I want is for someone to be able to come back to this form, see the values currently input and change them if need be.
Had the questions in the form been hard coded I would have simply done something like
for each option value in the dropdown so my form would be as such
but the questions are generated from a table in the database. How do I mark the questions as selected when I grab them from the database, then check to see whether the form has already been filled in?
Thanks
Code:
<form method='post' action='' id='form' name='form'>
<table>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Column 6</th>
<th>Column 7</th>
</tr>
<?php
$result = $this->Query("select * from mytable");
$position = 1;
while($row = $this->FetchArray($result[0]))
{
echo " <input type='hidden' name='q_".$position."' value='".$row['id']."' />
<tr>
<td>".$row['sg_code']."</td>
<td>".$row['sg_question']."</td>
<td><select name='SG".$position."score'><option value=''>- Please select -</option><option value='3'>3</option><option value='2'>2</option><option value='1'>1</option></select></td>
<td><input type='checkbox' name='sg".$position."witnessed' /></td>
<td><select name='SG".$position."'><option value=''>- Please select -</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option></select></td>
<td><input type='checkbox' name='sg".$position."pdp' disabled /></td>
<td><input type='checkbox' name='sg".$position."redflag' disabled /></td>
</tr>";
$position++;
}
?>
<tr>
<td colspan='7' height='6'>
Comments (optional)<br /><br />
<textarea name='sgcomments' class='textfieldlarge'></textarea>
</td>
</tr>
<tr>
<td colspan='7' align='right'>
<input type='submit' name='submit' value='Save' class="button">
</td>
</tr>
</table>
</form>
When this is filled in it saves to another table in the database.
What I want is for someone to be able to come back to this form, see the values currently input and change them if need be.
Had the questions in the form been hard coded I would have simply done something like
Code:
<?php if ($row['SG1'] == '1') { echo "selected "; } ?>
for each option value in the dropdown so my form would be as such
Code:
<td><select name='SG1'><option value=''>- Please select -</option>
<option value='1' <?php if ($row['SG1'] == '1') { echo "selected "; } ?>
>1</option>
<option value='2'<?php if ($row['SG1'] == '2') { echo "selected "; } ?>
>2</option>
<option value='3'<?php if ($row['SG1'] == '3') { echo "selected "; } ?>
>3</option>
<option value='4'<?php if ($row['SG1'] == '4') { echo "selected "; } ?>
>4</option>
...
</select></td>
but the questions are generated from a table in the database. How do I mark the questions as selected when I grab them from the database, then check to see whether the form has already been filled in?
Thanks