简体   繁体   English

使用PHP中的MySQL查询填充下拉列表

[英]Populate drop-down list with MySQL query in PHP

I want to use the following code to populate a drop-down list with all of the customer types: 我想使用以下代码填充包含所有客户类型的下拉列表:

<select name="type" id="type" class="neutral">
<?php   // SQL QUERY TO RETRIEVE EVERY TYPE OF CUSTOMER
$sql = "SELECT CUST_TYPE FROM `CUSTOMER` GROUP BY `CUST_TYPE`";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){echo '<option value="'.$row.'">'.$row.'</option>';}
                ?>

The query works in phpMyAdmin; 该查询在phpMyAdmin中工作; it gives the correct output (corporate, other, school, sports) but in the webpage it displays a drop-down list with 4 options, all containing the word "array." 它提供了正确的输出(公司,其他,学校,体育),但在网页上显示了一个包含4个选项的下拉列表,所有选项都包含“数组”一词。 Please help! 请帮忙!

Try 尝试

while($row = mysql_fetch_assoc($result)){
    echo '<option value="'.$row['CUST_TYPE'].'">'.$row['CUST_TYPE'].'</option>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM