little help with multi select..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rob1
Forum Newbie
Posts: 12
Joined: Mon Jul 28, 2008 10:05 am

little help with multi select..

Post by rob1 »

as im new to php i decided to build my own photo gallery system which will also give me a chance to use many fo the features in php and to help me learn.

so far ive managed to to build a basic gallery system where i can upload images to the server, make thumbnails and manipulate the images using gd library.

the next phase of the project is to create some kind of category tags, which i have managed to do with a multi select box, where i have created an IMAGE table, CATEGORY table and a CAT_IMG table to deal with multiple tags for multiple images... so when the items are selected in the box it submits the the values and (delete all records with selected image first), loops through each value in the array where i INSERT the ids into the CAT_IMG table.

this all works for me, although i could probably improve the process where i delete existing items then re-insert the newly selected ones - would love to get some advice on this if this is poor design

however the one thing thats got me confused is trying to use a html multi select box to preselect items that have been previously selected, so if i had 50 category tags the user wouldnt have tio reselect all of those again if they just wanted to add 1 item, would anyone be able to point me in the right direction, im sure i've overlooked something really simple :oops:
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: little help with multi select..

Post by Jade »

When you're building the multi-select box you need to put selected next to each item that has been highlighted.

Code: Select all

<select name="categories" multiple="multiple">
<option value="1">Kids</option>
<option value="2" selected>Nature</option>
<option value="3" selected>Animals</option>
<option value="4" selected>Rural</option>
</select>
Post Reply