<?php
//資料庫主機設定
$db_host = "localhost";
$db_username = "root";
$db_password = "123456";
$db_name = "mes_board";
//連線資料庫
$db_link = @new mysqli($db_host, $db_username, $db_password, $db_name);
//錯誤處理
if ($db_link->connect_error != "") {
echo "資料庫連結失敗!";
}else{
//設定字元集與編碼
$db_link->query("SET NAMES 'utf8'");
}
?>
<form id="form1" name="form1" method="post" action="">
<label>領域:
<select name="papermenu" id="papermenu">
<?php
$str="SELECT id,papermenu FROM menu ";
$list =mysql_query($str,$link);
?>
</select>
</form>
最近小弟我做到下拉式選單,有個疑問是連結資料庫後,這段要怎麼做才能讓我資料庫的papermenu的這個表單裡的選項用下拉式表單顯示出來呢?
<?php
$str="SELECT id,papermenu FROM menu ";
$list =mysql_query($str,$link);
?>
這段要怎麼做才能讓我資料庫的papermenu的這個表單裡的選項用下拉式表單顯示出來呢?
<select name="papermenu" id="papermenu">
<?php
$str="SELECT id,papermenu FROM menu ";
$list =mysql_query($str,$link);
while($list_row = mysql_fetch_array($list)){?>
<option value="<?php echo $list_row['papermenu'];?>"><?php echo $list_row['papermenu'];?></option>
<?php
}?>
</select>
其餘注意點與細節再靠自己慢慢挖掘囉