Home php How to make a dropdown list in php, data from mysql

How to make a dropdown list in php, data from mysql

Author

Date

Category

How to make a drop-down list next to the field for filling, which will show data from another table and, when pressed, write it into the field?

& lt; form method = "kolstud" action = "kolstud.php" & gt;
& lt; input name = "namebook" ty0or= "int" value = "book name" / & gt;
 & lt; input name = "FIOstud" type = "int" value = "Student name" / & gt;
 & lt; input type = "submit" name = "Submit2" value = "Add" / & gt;
& lt; / form & gt; // fields for data
$ namebook = $ _REQUEST ['namebook'];
$ FIOstud = $ _REQUEST ['FIOstud'];
$ insert = "INSERT INTO` kolstud` VALUES (
 (SELECT `idbook` FROM` book` WHERE `name` = '$ namebook'),
 (SELECT `idstudent` FROM` student` WHERE `FIO` = '$ FIOstud')
) "; // request to add

Answer 1

& lt; select name = "book" & gt;
  & lt; option value = "0" & ​​gt; Select a book & lt; / option & gt;
& lt ;?
$ res = mysql_query ('select `id`,` name` from `books`');
while ($ row = mysql_fetch_assoc ($ res)) {
  ? & gt;
  & lt; option value = "& lt;? = $ row ['id']? & gt;" & gt; & lt;? = $ row ['name']? & gt; & lt; / option & gt;
  & lt ;?
}
? & gt;
& lt; / select & gt;

Something like this. Why do you have input type = “int”?
And if you want to make a button like in Joomla, use css to place the text field above the select so that only the arrow sticks out.

Added

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions