View Full Version : Help with updating a DB after changes

12-10-2008, 06:53 PM
suppose I have a site where a person can choose a car and some colors. A user enters the following information:

mustang - red
mustang - blue
mustang - green
mustang - orange

On the same website, there is a form that allows a user to update their previous choices. So a few days later the same user makes the following changes to their selection:

mustang - red
mustang - blue
mustang - black

I'm curious as to what you think would be the best way to code something like this to update the mysql DB. I want the red and blue to not change. The green and orange needs to be deleted. Black needs to be added.

I understand the core logic itself. But I'm getting hung up on the best way to streamline some code for this. Bunch of ifs? Case statement? Any ideas would be great because you'll probably spark something that I'm just not feeling right now.


12-10-2008, 08:32 PM
This may be the "lazy" way to do it (i.e. more processing time but coding is simple), but I would DELETE all of that user's previous entries and INSERT the new settings. I doubt anyone would ever notice the extra time it takes (unless the user has hundreds of settings).