php and mysql form

Hi all, how I can add values ​​in a table to a combo box in html .. eg: the user's table has the id 1,2,3,4 and that using a query, being able to move to a combo box, to make a selection of id?.

Greetings and thank you very much.

Member Avatar
diafol

0. initialise a variable, $options="";
1. retrieve the data with SELECT...
2. set up a loop (while) on the result object
3. concatenate the $options var in the loop, building up the list:

while...
set the $id from the result object
$options .= "\n\t<option value=\"$id\">$id</option>";
..end loop

<select>
echo out the $options
</select>

thanks, I is working.
Now, as I can get that data selected to insert into another table.

For example.

$sql="INSERT INTO CARRERA (id,Hora,Ruta,CHOFER_idChofer,BUS_idBUs)
VALUES
('$_POST[id]','$_POST[Hora]','$_POST[Ruta]','$_POST[CHOFER_idChofer]','$_POST[BUS_idBUs]')";

using the POST, I get the value of a textbox. and insert it to my table.
as I do that but in the combo box

Thank you very much for your help

using the POST, I get the value of a textbox. and insert it to my table.
how to do that but in the combo box?

Thank you very much for your help