Forums

PHP

This topic is locked

multiple selection insert

Posted 14 Aug 2002 03:20:48
1
has voted
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
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>
&lt;select name="fact_sheets" size="5" multiple&gt;
&lt;option value="1" &lt;?php if (!(strcmp($row_Recordset1['fact_sheets'], 1))) {echo "SELECTED";} ?&gt;&gt;one&lt;/option&gt;
&lt;option value="2" &lt;?php if (!(strcmp($row_Recordset1['fact_sheets'], 2))) {echo "SELECTED";} ?&gt;&gt;two&lt;/option&gt;
&lt;option value="3" &lt;?php if (!(strcmp($row_Recordset1['fact_sheets'], 3))) {echo "SELECTED";} ?&gt;&gt;three&lt;/option&gt;
&lt;/select&gt;</font id=code></pre id=code>

Where exactly would I use the implode function to dump the multiple selections into a db?

Reply to this topic