好的我有一个选择框(下拉菜单)和一组单选按钮。
选择您的班级:
<form action="" method="post">
<select name="class">
<option value="a">A</option>
<option value="b">B</option>
</select>
<br><br>
Red or blue:<br>
<input type="radio" name="red" value="red">Red
<input type="radio" name="blue" value="blue">Blue
</form>
我已将PHP脚本连接到数据库并从表中检索数据并将其存储在变量中以进行回显。 ROW是Mysql fetch数组。
$class = $row['class']
$color = $row['color']
如何在单选按钮和选择框中显示它(通常用于文本框我将值设置为
<? php echo $foo ?>
有人可以帮助我吗?
答案 0 :(得分:0)
//read the data from database
$row=mysql_fetch_row($result);
//assuming that the first data cell fetched is for dropdown list and the second is for radio button thats why $row[0] and $row[1] is used
<form action="" method="post">
<select name="class">
<option value="a" <?php if($row[0]=='a'){?> selected <?php } ?> >A</option>
<option value="b" <?php if($row[0]=='b'){?> selected <?php } ?> >B</option>
</select>
<br><br>
Red or blue:<br>
<input type="radio" name="red" value="red" <?php if($row[1]=='red'){?> checked<?php } ?>>Red
<input type="radio" name="blue" value="blue" <?php if($row[1]=='blue'){?> checked<?php } ?>>Blue
</form>