The question is: what should be in the for loop, so that the departments register in the drop-down list?
In the MySQL database there are two tables prepods and cafedrs. The prepods table consists of two fields - prepod and cafedra. The cafedra is also in the cafedrs table, which is already full. Tables are related.
You need to create a form for entering the prepods table in PHP, so that the field of the department in the table is a drop-down list and all values of this field are taken from the cafedrs table (the cafedra field).
php code
<?php if ($_POST["submit"]) { if (!($connection=mysql_connect ("localhost", "root", "2357610"))) die ("Нет соединения"); if (!(mysql_select_db ("imc", $connection))) die ("База ИМЦ не выбрана"); $prepod=$_POST['prepod']; $cafedra=$_POST['cafedra']; if (!($cafedra=mysql_query ("SELECT cafedra from cafedrs"))) die ("Ошибка"); $count=mysql_num_fields ($cafedra); while ($row=mysql_fetch_array ($cafedra)) { for($x=0;$x<$count;$x++) {//здесь нужно что-то сделать} } if (($cafedra!="") or ($prepod!="")) { $sql=mysql_query("INSERT INTO prepods VALUES (null,'$prepod','$row[$x]',1)"); $result=mysql_query($sql); echo "<script type=\"text/javascript\"> alert(\"Данные добавлены\");</script> \n"; } else { echo "<script type=\"text/javascript\"> alert(\"Заполните поля\");</script> \n"; }; } ?>
The form itself:
<form action="pre.php" method="POST" name="form1"> <table width="100%" align="center" valign=center> <tr> <td align=right>ФИО преподавателя:</td> <td> <input type="text" name="prepod"> <br> </td> </tr> <tr> <td align=right>Наименование кафедры:</td> <td> <select name="row"></select> <br> </td> </tr> <tr> <td align=right> <br> <input type="submit" name="submit" value="Сохранить"> </td> </tr> </table> </form>