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

RSS Twitter

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

by: John Della Pia
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. 

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 ();

Comment and Contribute

Your comment has been submitted and is pending approval.

John Della Pia



(Maximum characters: 1200). You have characters left.