Jump to content

Archived

This topic is now archived and is closed to further replies.

maziagha

Multiple inserts into MYSQL via list/menu

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
I guess I'd have a database structure like:
id int autoincrement
dropdown - varchar - some convenient name for the dropdown
sel_name varchar - the name of the select used in its dropdown, name="whatever"
sel_opts text

In 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 loop
echo "<select name='". $sel_name. "'>/n";
for ($i=0;$i<count($opts);$i++) {
    echo "<option value='". $i. "'>". $opts[$i]. "</option>/n";
}
echo "</select>";
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.