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.
//jdellapia@imediaempires.com
function your_dropdown ()
{
$top=<<<top
<select name="dropdown" id="dropdown">
<option value=""></option>
top;
$footer="</select>";
echo"$top";
$query = "SELECT some_value1, some_value2 FROM table";
$result=MYSQL_QUERY($query);
while ($name_row = mysql_fetch_row($result))
{
$name = $name_row[0];
$id = $name_row[1];
$select=<<<sel
<option value="$id">$name</option>
sel;
echo"$select";
}echo"$footer";
}
//call the function somewhere
your_dropdown ();