maziagha Posted September 6, 2006 Share Posted September 6, 2006 Helo!I use this script to get a dropdown from my mysql. this works fine. what the problem is that i want to have multiple dropdowns and all the selected values should be stored in the same table, but each value as a new row[code]<?php $sql="select * from tbl_sizes";$result=mysql_query($sql);echo "<select name=\"select\">\n";while($zeile = mysql_fetch_array($result)){?><option value="<?php echo $zeile['SizeChartID']; ?>"><?php echo $zeile['Size'];?></option><?php}?>[/code]How can i do that? Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 6, 2006 Share Posted September 6, 2006 I'm not too sure I understand that. Do you mean you would like to have each row contain the 'name' for a particular select/list box and the names of each of the options that belong to that dropdown? Quote Link to comment Share on other sites More sharing options...
maziagha Posted September 6, 2006 Author Share Posted September 6, 2006 yes exactly :) Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 6, 2006 Share Posted September 6, 2006 I guess I'd have a database structure like:id int autoincrementdropdown - varchar - some convenient name for the dropdownsel_name varchar - the name of the select used in its dropdown, name="whatever"sel_opts textIn use, I'd make sel_opts a simple comma separated list that I would retrieve from the database, then explode into its component. Approximately, and untested:[code]// sort of// connected to database$which = "animals"; // the 'convenient' name of the dropdown I want$query = "SELECT * from dropdowns_table WHERE dropdown = '$which'";$result = mysql_query($query);$row = mysql_fetch_array($result);extract $row;$opts = explode("," $sel_opts) ; // abstract individual options from comma-separated list// do select loopecho "<select name='". $sel_name. "'>/n";for ($i=0;$i<count($opts);$i++) { echo "<option value='". $i. "'>". $opts[$i]. "</option>/n";}echo "</select>";?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.