我有一个简单的表单,其中包含四个文本区域和一个单选组,每个文本区域旁边都有一个单选按钮。
<form action="" method="post" id="form">
<table width="35%" border="0" align="left" cellpadding="5">
<tr>
<td valign="top">Pathway</td>
<td valign="top">Allowed
<br />(One only)</td>
<td valign="top">Comment</td>
</tr>
<tr>
<td valign="top">2. No action. See again</td>
<td valign="top"><input type="radio" name="pathway" value="y" id="pathway_1" /></td>
<td valign="top"><textarea name="pathway_comment[]" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td valign="top">2. See again</td>
<td valign="top"><input type="radio" name="pathway" value="y" id="pathway_2" /></td>
<td valign="top"><textarea name="pathway_comment[]" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td valign="top">3. Refer to ED</td>
<td valign="top"> <input type="radio" name="pathway" value="y" id="pathway_3" /></td>
<td valign="top"><textarea name="pathway_comment[]" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td valign="top">4. Refer to specialist</td>
<td valign="top"><input type="radio" name="pathway" value="y" id="pathway_4" /></td>
<td valign="top"><textarea name="pathway_comment[]" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="3" valign="top"><input type="submit" name="define_pathways" id="submit" value="Add Pathways" /></td>
</tr>
</table>
</form>
每个文本区域 ($_POST['pathway_comment']) 的内容通过循环作为单独的记录插入到 MySQL 表中:
$pathway = $_POST['pathway'];
$pathway_comment = $_POST['pathway_comment'];
if(isset($_POST['define_pathways'])){
for($i=0, $count = count($pathway_comment);$i<$count;$i++) {
$comment = $pathway_comment[$i];
$query_level_1 = "INSERT INTO pathway (pathway_pk,case_fk,level,pathway_allowed,comment)
VALUES ('','$vcase','1','$pathway','$comment')";
$result_level_1 = mysql_query($query_level_1, $connection) or die(mysql_error());
}
表结构:
`pathway_pk` int(4) NOT NULL AUTO_INCREMENT,
`case_fk` int(3) NOT NULL,
`level` int(1) NOT NULL,
`pathway_allowed` char(1) NOT NULL DEFAULT 'n',
`comment` text NOT NULL,
现在在插入时,我想将pathway_allowed
四个记录之一设置为“y”,而将其他记录保留为默认的“n”。我怎样才能做到这一点??