How to populate HTML dropdown list with values from database

后端 未结 6 1287
南笙
南笙 2020-11-30 02:35

as part of a HTML form I am creating I would like to have a dropdown list which will list all the usernames in my database.

I thought the following code would do the

6条回答
  •  春和景丽
    2020-11-30 03:14

    Use OOP concept instead. Create a class with function

    class MyClass {
    
    ...
    
    function getData($query) {
        $result = mysqli_query($this->conn, $query);
        while($row=mysqli_fetch_assoc($result)) {
            $resultset[] = $row;
        }       
        if(!empty($resultset))
            return $resultset;
    } }
    

    and then use the class object to call function in your code

    getData("select city_name from city"); 
    ?>
    
    

    Full code and description can be found here

提交回复
热议问题