Jump to content


Photo

Multiple inserts into MYSQL via list/menu


  • Please log in to reply
3 replies to this topic

#1 maziagha

maziagha
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 06 September 2006 - 09:03 AM

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
<?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
}
?>

How can i do that?


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 06 September 2006 - 09:08 AM

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?
Legend has it that reading the manual never killed anyone.
My site

#3 maziagha

maziagha
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 06 September 2006 - 09:47 AM

yes exactly :)

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 06 September 2006 - 09:58 AM

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:

// 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>";
?>

Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users