|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Multiple select and mySQL
Hello people.
I love the turtorials on this site. Finally Im starting to get a hang of PHP and mySQL. Im fooling around with the "Create dynamic sites with PHP & MySQL" turtorial. I want to add a user category list. Users should be able to be in many categories. I have coded the form to use for displaying the diffrent categories available. But I got problems figuring out how to store which category each user have selected. I have set the categories up in its own table. And Im usig this code to show the categories. while ($own_row=mysql_fetch_array($own_result)) { echo "<select name="categories" size="10" multiple>"; echo " <option value="".$own_row["category_id"]."">".$own_row["categories"]."</option>"; } echo "</select>"; But when I submit the form, only the last selected category is stored in mySQL. |
|
#2
|
|||||
|
|||||
|
RE: Multiple select and mySQL
try setting a name of your select to 'categories[]' like this:
and then u can use foreach in your php script to see all the selected categories, like this: php Code:
|
|
#3
|
|||
|
|||
|
RE: Multiple select and mySQL
Thanks, so I could then pipe the array and pass it to mySQL. Interesting....
Thanks m8 |
|
#4
|
|||
|
|||
|
RE: Multiple select and mySQL
if you want to store the selection in a database or file, use this peice of code.
(ive modded it to work with your vars) var $cats; foreach($categories as $id) { $cats .= $id . ','; } $cats = substr($cats, 0, -1); that way it will print out your array as something like this: $cats = row1,row3,row6 //what ever you have selected then you can store it in a database, then when you want to grab the array, just explode it |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Multiple select and mySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|