下拉菜单两种方式

一.

<select>
<?php
$db=new MySQLi("localhost","root","root","zuoye");
$sql="select * from fruit";
$result=$db->query($sql);
while( $arr=$result->fetch_row())
{
echo "<option value=‘{$arr[0]’>{$arr[1]}</option>";
}
?>
</select>
二.
<?php
echo "<select>";
echo "<option>请选择</option>";
$db=new MySQLi("localhost","root","root","zuoye");
$db->query("set names UTF8");
$sql="select*from fruit";
$result=$db->query($sql);
$arr=$result->fetch_all();
foreach($arr as $v)
{
echo"<option value=‘{$arr[0]}’>{$arr[1]}</option>";
}

echo "</select>";
?>

posted @ 2017-05-03 14:39  张小琪  阅读(128)  评论(0编辑  收藏  举报