PHP - MYSQLI:从db动态选择属性并在下拉列表中显示

时间:2016-03-29 19:29:14

标签: php mysql mysqli

我正在尝试从我的数据库中选择类别名称并在下拉列表中显示它们。我不明白为什么我的代码不起作用。 字面上的下拉列表仅显示"选择类别"没有别的。它也使它消失后的所有字段。

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

我哪里出错了?

1 个答案:

答案 0 :(得分:0)

代码中的错误是您使用mysql_fetch_array()时应该是mysqli_fetch_array()。请注意丢失的i