我已连接到我的数据库。创建了一个下拉框。哪个工作正常:
$sql = "SELECT * FROM Customer";
$result = mysql_query($sql);
echo "<b>Customer Name : </b>" . "<select id='CustomerName' name='CustomerName'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['CustomerName'] . "'>" . $row['CustomerName'] . "</option>";
}
现在我被困在尝试将表客户的值放入数组中 看起来像这样:
$types = array (
'A' => 10.99,
'B' => 4.99,
'C' => 13.99);
我打算做的是创建这个数组,其中,代替 A B C,用 CustomeName 和 CustomerPrice 代替价格。"客户"表具有
+----------------+-----------------+---------------+
| Customer_ID | CustomerName | CustomerPrice |
+----------------+-----------------+---------------+
| 1 | A | 10.99 |
| 2 | B | 4.99 |
| 3 | C | 13.99 |
+----------------+-----------------+---------------+
请帮忙
除了生成数组之外,您基本上执行与下拉列表相同的操作。您可以在同一个循环中执行此操作:
$sql = "SELECT * FROM Customer";
$result = mysql_query($sql);
$array = array();
echo "<b>Customer Name : </b>" . "<select id='CustomerName' name='CustomerName'>";
while ($row = mysql_fetch_array($result)) {
$array[$row['CustomerName']] = $row['CustomerPrice'];
echo "<option value='" . $row['CustomerName'] . "'>" . $row['CustomerName'] . "</option>";
}
希望这有帮助