How to save from multiple listbox to database

I have a many-many relationship.

I have an activeListBox on my form, and display the list of "neighborhoods".

It is also correctly selecting the correct (multiple) neighborhoods.

However, if I change the selection, this is not updated in the database.

What do I need to do to fix this?

Apache/2.2.11 (Win32) PHP/5.3.0 Yii Framework/1.1.5 2010-11-26 01:04

MySql 5.1.36

Are you sure that in $POST you have the correct value?

If yes, are you sure that there is some rule on the attribute you are going to change?

In my opinion, the listBox is an unconfortable instrumet, I like much more to write custom code and use a third table for the relationship instead of save on db comma separated values.

I don’t know the answer to your other questions, but I am using three tables:




with foreign keys

In that case, sorry I didn’ get your initial question…

How are you proceeding? Can you explain a bit more what is your goal and how you are trying to achive?

Maybe I can help you a bit more…

delete all records in location_neighborhood with corresponding locationId, insert all selected neighborhood items

(foreach $_POST[‘form’][‘neighbors’] as $neighbor)

So, this feature is not built in then, correct?

Which event should I handle to do this?

A location (it’s a restaurant) can “serve” multiple locations. So, there’s a list of locations:




And a list of neighborhoods:




And a connecting table:


location_id (foreign key to LOCATION)

neighborhood_id (foreign key to NEIGHBORHOOD)

Then, the user is presented with a list (multiple select) of the neighborhoods that their location serves, and they can change them in the multiple select box, and this should be saved to the database. I guess I just need to know which event to handle, and it looks like I should delete all the records for that location in LOCATION_NEIGHBORHOOD, then insert the "new" ones.

PS I’m an experienced ASP/Javascript/MSSQL programmer, but am very new to Yii, and reasonably new to PHP/MySql

Can I get some help please?

I thought I saw something about an advanced AR behavior, can I use that?