我已經寫了一些代碼,用數據庫中的數據填充單選按鈕。雖然我在這段代碼中遇到了一些問題,但對於一個表單,我可以一次選擇多個單選按鈕,而不應該這樣做。另一個問題是,除了按鈕本身之外,顯示的文本是來自表中「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