Answer the question
In order to leave comments, you need to log in
Data output from a DB through DropDown or the list?
Hello everyone, it was necessary to display data from the database through a drop-down list, there is data in the database, but I can’t display it in any way.
<select>
<option>Выбор ответсвенного</option>
<?php
$EmpNames ="SELECT user_id FROM users";
foreach ($EmpNames as $Emp) {
?>
<option><?php echo $Emp;?></option>
<?php }?>
</select>
Answer the question
In order to leave comments, you need to log in
// для начала надо подключиться к базе данных
mysql_connect('hostname', 'username', 'password'); // пароль, логин , хост нейм для подключения к базе
mysql_select_db('database-name'); // название базы
// если в процессе подключения к БД есть ошибки - нужно разобраться и
// исправить (в тектсе ошибки будет подсказка)
$sql = "SELECT user_id FROM users";
$result = mysql_query($sql);
echo "<select name='user_id'><option>Выбор ответсвенного</option>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['user_id'] . "'>" . $row['user_id'] . "</option>";
}
echo "</select>";
Access to the database is usually carried out using the driver of the desired database. For example MySQLi , PostgreSQL .
Extensions for working with databases of individual pr...
You will also find examples of use there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question