Filling combobox values

Hello! How to make the combobox populate the list with values from a table in a MySQL database?


Answer 1, authority 100%

$db = new PDO($connectionString, $user, $pass);
$res = $db->query(“SELECT id, name FROM table”);
echo "<select name='var'>";
while ($obj = $res->fetch(PDO::FETCH_OBJ)) {
    // $obj -   stdClass,   -  
    echo "<option value='{$obj->id}'>{$obj->name}</option>"
}
echo "</select>";

This is how you can make a dropdownlist. (combobox?)

Leave a reply

Please enter your comment!
Please enter your name here