Page 1 of 1

drop down menus

Posted: Mon Mar 20, 2006 2:11 am
by sangeetha
Hi
i am new to PHP. I am using MySQl database. In my database i have a list of products which i want to dispaly in a form as a drop-down menu.
The problem is I dont know how to link my table frield to drop down menu.
Later i want to pass the selection from drop-down menu to PHP action script. How can i do that?

pls help me.

thanks in advance

Posted: Mon Mar 20, 2006 4:23 am
by s.dot
#1 query your sql statement
#2 build your form element
#3 loop through your query results

like this

Code: Select all

$result = mysql_query("SELECT `foo` FROM `bar`");

echo "<select>";
while($array = mysql_fetch_array($result)){
   echo "<option value=\"{$array['foo']}\">{$array['foo']}</option>\n";
}
echo "</select>";

Posted: Mon Mar 20, 2006 12:16 pm
by a94060
ha,thanks,this helped me also. :wink: