472,119 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Updating selected options Logic

2
Hi!,
can some help me with a problem?

Here are my tables: User, Profiles, and one for "Profiles per user"

In the last one, I save the ID of the user and the ID of the profiles for that user. This profiles are selected through checkboxes. My question is, What's the best way to update the records on the database?,
because there's three scenarios, they selected a new profile (INSERT), they leave like it was (NOTHING), or they unselected a profile (DELETE).

But I can't figure out a "nice" way to do this. Should I just erase all the records from the table, and then insert all the new ones even if there are unchaged records?,
Any ideas?
Mar 17 '08 #1
3 1196
ck9663
2,878 Expert 2GB
This would mean there can be multiple profiles per user.

Why don't you just add a ProfileStatus field that you can just change to 0 for Inactive simulating a DELETE and 1 for active simulating an INSERT or a reactivation of a profile.

For me, this would take 2 steps. INSERT those that are not yet on the profile and activate those SELECTED (if the record is currently selected it will overwrite the same value - which is 1).

-- CK
Mar 18 '08 #2
Assuming that you want a user to have many profiles, there is more than one way to do this.

One:
The user presses "Save", and their information is deleted from the database, and the new information saved. This is the option you have mentioned.

Two:
The user presses "Save". The code (eg .NET) checks for profiles that have been marked as "Delete", and deletes them. The code checks for profiles that have been added, and adds them. The code then updates the rest.

Three:
There is a "Save" button on each Profile line on the screen, and the user saves after each change. This will make it easier for you to manage, but I guess it depends how many changes the user makes at one time. They might get sick of pressing the "Save" button after a while.

There is no right answer here. They are all valid choices. Personally, I would either go for option one and make sure I wrapped it in a transaction in case something went wrong half way through, or go for option two.

Hope this helps
Mar 19 '08 #3
royd16
2
Ok, Thanks! I just want to use the option that gives me the best performance gain.
seeing this options I think I'll try option number two.

Thanks again
Mar 19 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by Jason | last post: by
5 posts views Thread by Raffi | last post: by
1 post views Thread by smash2004 | last post: by
7 posts views Thread by webmaster | last post: by
14 posts views Thread by el_sid | last post: by
3 posts views Thread by John Walker | last post: by
2 posts views Thread by Rob Long | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.