All expensive time of day. The site has fields with a drop-down list, the field is used so that the user can select the desired city in the questionnaire.

<select class="row-item-2"> <option>Город</option> </select> 

The database in the bd_city table has a list of cities with such id and name fields.

The site is connected to the database

 require_once 'config.php'; // подключаем скрипт // подключаемся к серверу $link = mysqli_connect($db_host, $db_user, $db_pass, $db_name) or die("Ошибка " . mysqli_error($link)); // выполняем операции с базой данных // закрываем подключение mysqli_close($link); 

Tell me, please, how can I get cities to the drop-down list?

    1 answer 1

    Used such a method found on the Internet. It helped.

     <?php // Подключение к базе данных MySQL. @$on_link = mysqli_connect($db_host, $db_user, $db_pass); if (!$on_link) { echo "Ошибка соединения с сервером MySQL!"; exit; } // изменение набора символов на utf8 mysqli_set_charset($on_link, "utf8"); // Выбираем БД для работы в MySQL. @$db_select = mysqli_select_db ($on_link, $db_base_ref); if (!$db_select) { echo "Не удалось выбрать БД MySQL."; exit; } // Делаем выборку из таблицы. $sql = "SELECT * FROM `access`"; $result_select = mysqli_query($on_link, $sql); echo "<select name = '1234'>"; echo "<option value='0'>Выбор</option>"; while($object = mysqli_fetch_object($result_select)){ echo "<option value = '$object->id' > $object->name </option>";} echo "</select>"; ?>