日期:2014-05-17  浏览次数:20432 次

下拉列表的数据怎样动态读取数据库字段的内容?
select name="cp_kh" id="selModule">
      <option value="{$row[$i]}"></option></select>

点击下拉列表时,下拉列表的数据是从数据库动态取来的。要用什么方法才能从数据库表取某个字段下面所有行的数据给下拉列表。下拉列表按读取的数据一行很排列。php读取数据表字段,把读取的数据赋值给下拉列表。(怎么实现?)如下图,
PHP 数据库

------解决方案--------------------

    <td width="100px;">车种</td>
<td><select name="cartype" style="width:90px;" />
  <?php
$sql="select * from cartype";
$query=mysql_query($sql);
while($result=mysql_fetch_array($query)){
?>
<option value="<?=$result[cartype]?>"><?=$result[cartype]?></option>
<?php
}
?>
</select></td>