Forums
This topic is locked
multiple selection insert
14 Aug 2002 03:20:48 Man CHAN posted:
Hi there,I'm made a insert page for recording people favorite sports. There is a
list/menu for multiple selection (Basketball, Volleyball, Tennis, Swimming).
If I choose Basketball, Volleyball and Tennis at the same time and then press submit the database only store 'Tennis'.
The following is mySQL structure:
Create table sports(
sport set ('Basketball', 'Volleyball', 'Tennis', 'Swimming')
)
What wrong of my process? Thanks
Replies
Replied 14 Aug 2002 09:50:26
14 Aug 2002 09:50:26 Michael Guntenaar replied:
Hmm, that's kinda logic, you have to work with arrays in this case.
Make your form field like this
<input type="meep" name="zone[]">
When you submit your form there is an array called zone.
From there you have to do some tricks with this array.
Like if you want to store the values comma separated use PHP's implode function.
<pre id=code><font face=courier size=2 id=code>
$comma_separated = implode(",", $zone);
</font id=code></pre id=code>
If your array (zone) contains two sports like football and tennis
Your variable $comma_separated will print the following output
football, tennis <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
I hoped this helped ya <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Edited by - mguntenaar on 14 Aug 2002 09:51:27
Make your form field like this
<input type="meep" name="zone[]">
When you submit your form there is an array called zone.
From there you have to do some tricks with this array.
Like if you want to store the values comma separated use PHP's implode function.
<pre id=code><font face=courier size=2 id=code>
$comma_separated = implode(",", $zone);
</font id=code></pre id=code>
If your array (zone) contains two sports like football and tennis
Your variable $comma_separated will print the following output
football, tennis <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
I hoped this helped ya <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Edited by - mguntenaar on 14 Aug 2002 09:51:27
Replied 03 Feb 2003 20:46:05
03 Feb 2003 20:46:05 A D replied:
I've read other posts on this ... but I'm still foggy. This reply was the best I saw.
I'm confused though. Here's a form I'm working with:
<pre id=code><font face=courier size=2 id=code>
<select name="fact_sheets" size="5" multiple>
<option value="1" <?php if (!(strcmp($row_Recordset1['fact_sheets'], 1))) {echo "SELECTED";} ?>>one</option>
<option value="2" <?php if (!(strcmp($row_Recordset1['fact_sheets'], 2))) {echo "SELECTED";} ?>>two</option>
<option value="3" <?php if (!(strcmp($row_Recordset1['fact_sheets'], 3))) {echo "SELECTED";} ?>>three</option>
</select></font id=code></pre id=code>
Where exactly would I use the implode function to dump the multiple selections into a db?
I'm confused though. Here's a form I'm working with:
<pre id=code><font face=courier size=2 id=code>
<select name="fact_sheets" size="5" multiple>
<option value="1" <?php if (!(strcmp($row_Recordset1['fact_sheets'], 1))) {echo "SELECTED";} ?>>one</option>
<option value="2" <?php if (!(strcmp($row_Recordset1['fact_sheets'], 2))) {echo "SELECTED";} ?>>two</option>
<option value="3" <?php if (!(strcmp($row_Recordset1['fact_sheets'], 3))) {echo "SELECTED";} ?>>three</option>
</select></font id=code></pre id=code>
Where exactly would I use the implode function to dump the multiple selections into a db?