#native_company# #native_desc#

PHP & MySQL Code sample for utilizing dynamic drop-down val

By John Della Pia
on February 17, 2006

Version: 6

Type: Full Script

Category: Databases

License: GNU General Public License

Description: Dear Sir/Madam,

Good Morning, I am new to PHP & I need some help. I am working on one online Data Entry form in which some fields contains drop-down values and I want to populate those values directly from MySQL tbl. I have total 7-8 fields in same way. & Some reason, it’s not giving me correct output. Also, if I try to run this simple piece by itself, it does give me values and when I include in HTML file, it doesn’t work for me: the code I’m copying below: When you’ve time, can you please advise me on this?

Thank you very very much in an advance.
Have a nice day!

//assuming you have established your database connection. 
//[email protected]

function your_dropdown ()
<select name="dropdown" id="dropdown">
 <option value=""></option>
$query = "SELECT some_value1, some_value2 FROM table";
while ($name_row = mysql_fetch_row($result))
	$name = $name_row[0];
	$id = $name_row[1];
      <option value="$id">$name</option>

//call the function somewhere
your_dropdown ();