我已经写了一些代码,用数据库中的数据填充单选按钮。虽然我在这段代码中遇到了一些问题,但对于一个表单,我可以一次选择多个单选按钮,而不应该这样做。另一个问题是,除了按钮本身之外,显示的文本是来自表中“customerID”列的值,当它应该来自表中“lastName”列的值和单选按钮的值应该是“customerID”字段看起来不错。如果您想知道表中列的实际结构,“customerID”列是第一位,“firstName”是第二位(但在此形式中不需要),“lastName”位于第三位。填充单选按钮?
这里是我当前的代码:
<?php
$conn = mysql_connect("localhost", "twa312", "dam6av9a");
mysql_select_db("warehouse312", $conn)
or die ('Database not found ' . mysql_error());
$sql = "select customerID, lastname from customer";
$rs = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
while ($row=mysql_fetch_array($rs)) {
$options .= '<input type="radio" id="custID" name="custID" value="'.$row[0].'" />'.$row[1];
}
?>
<form method="GET" action="task8.php" id="custinfo">
Choose name:<?php echo $options; ?><br>
<p><input type="submit" name="submit" value="Submit"/> <input type="reset" value="Reset" />
</form>
与解决这个任何帮助将是真正伟大的!
为什么你不按字段名称获取列值($ row ['customerID']) – lvil 2013-05-07 08:28:10