简体   繁体   中英

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

<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() . Notice the missing i .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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