Jump to content

Multiple inserts into MYSQL via list/menu


maziagha

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.