我有一个 Material 表,其中所有 Material 都被插入到 desc 列中。 desc 值可以尽可能多。
示例:
desc
poly canvass
metal
washer
knot
这是我做的代码。
<?php
$resource=mysql_query("Select * from material",$con);
while($result2=mysql_fetch_array($resource))
{
?>
<select>
<option value="<?php echo $result2[desc] ?>"><?php echo $result2[desc] ?></option>
</select>
</tr>
<?php };?>
但它会生成四个下拉列表,分别对应我数据库中的四个值 喜欢:
dropdown1 dropdown2 dropdown3 dropdown4
polycanvass metal washer knot
如何使 desc 列中的所有值出现在一个下拉列表中?
最佳答案
<?php
$resource=mysql_query("Select * from material",$con);
?>
<select>
<?php
while($result2=mysql_fetch_array($resource))
{
?>
<option value="<?php echo $result2[desc] ?>"><?php echo $result2[desc] ?></option>
<?php
}
</select>
?>
select 应该在 while 循环之外,因为对于每个值它也会重复,并且您最终会得到与总记录数一样多的下拉菜单。
关于php - 将数据库中的所有值调用到下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21261085/