Hi All, I am new in PHP. I want to retrieve value from database into a combo-box. How will i do this? Please give me the code to do this. and what will i write in html side <select> <option> </option></select> please help me to do this.
I want fetch values from a table , in database i have a table which name is "hostel_name" now i am making a combo-box in the form and i want to fetch values from "hostel_name" when i click on the combo the list of all "hostel_name" i get which are stored into the table"hostel-name". please help
Assuming you already connected to the DB, and make sure to replace the yourfield with the column name of what you want to fetch. <?php $query="SELECT * FROM hostel_name"; $res=mysql_query($query) or die(mysql_error()); echo '<select>'; while($row=mysql_fetch_array($res)) { echo '<option value="'.$row['yourfield'].'">'.$row['yourfield'].'</option>'; } echo '</select>'; ?> Code (php):