简体   繁体   English

PHP-MYSQLI:从数据库中动态选择属性并在下拉问题中显示

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

I am trying to select category names from my db and display them in a dropdown. 我试图从数据库中选择类别名称,并在下拉列表中显示它们。 I cannot see why my code is not working. 我看不到为什么我的代码无法正常工作。 The drop down literally only displays "select category" and nothing else. 下拉菜单实际上仅显示“选择类别”,而没有其他内容。 It also makes all the fields after it disappear. 它也使它之后的所有字段消失。

HTML/PHP 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>

TABLE

   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

where have i gone wrong? 我哪里出问题了?

The error in the code is that you are using mysql_fetch_array() when it should be mysqli_fetch_array() . 代码中的错误是您正在使用mysql_fetch_array()时应使用mysql_fetch_array() mysqli_fetch_array() Notice the missing i . 注意丢失的i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM