gpt4 book ai didi

PHP-MYSQLI : dynamically select attributes from db and display in dropdown issues

转载 作者:行者123 更新时间:2023-11-29 21:11:55 24 4
gpt4 key购买 nike

我正在尝试从我的数据库中选择类别名称并将其显示在下拉列表中。我不明白为什么我的代码不起作用。下拉列表实际上只显示“选择类别”,没有其他内容。它还会使它后面的所有字段消失。

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(),而它应该是mysqli_fetch_array()。请注意缺少的 i

关于PHP-MYSQLI : dynamically select attributes from db and display in dropdown issues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36293447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com