[英]PHP - MYSQLI : dynamically select attributes from db and display in dropdown issues
我試圖從數據庫中選擇類別名稱,並在下拉列表中顯示它們。 我看不到為什么我的代碼無法正常工作。 下拉菜單實際上僅顯示“選擇類別”,而沒有其他內容。 它也使它之后的所有字段消失。
HTML / PHP
<select name="cats">
<option>Choose cuisine</option>
<?php
$get_cats = "SELECT * FROM Rest_Category";
$run_cats = mysqli_query($dbc,$get_cats);
while ($row_cats = mysql_fetch_array($run_cats)) {
$CategoryID = $row_cats['CategoryID'];
$Cuisine_category = $row_cats['Cuisine_category'];
echo"<option value='$CategoryID'>$Cuisine_category</option>";
//echo "<option value=\"owner1\">" . $row['Cuisine_category'] . "</option>";
}
?>
</select>
表
CREATE TABLE `Rest_Category` (
`CategoryID` smallint(11) NOT NULL AUTO_INCREMENT,
`Cuisine_category` enum('African','Alcohol','American','Asian Fusion','Breakfast',
'British Roast','Bubble Tea','Burgers','Cakes & Desserts',
'Caribbean','Chicken','Chinese','Coffee','Cupcakes','European','Fish & Chips',
'Five Guys','Fried Chicken','Gourmet','Greek','Ice Cream','Italian','Indian',
'Jamaican','Juice','Krispy Kreme','Turkish') NOT NULL,
`Category_img` varchar(45) NOT NULL,
PRIMARY KEY (`CategoryID`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
我哪里出問題了?
代碼中的錯誤是您正在使用mysql_fetch_array()
時應使用mysql_fetch_array()
mysqli_fetch_array()
。 注意丟失的i
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.