Jump to content

Archived

This topic is now archived and is closed to further replies.

XenoPhage

Algorithm Question

Recommended Posts

Hey all,

I have a select multiple box. In that box are a number of options. The user chooses options and then the back end saves them to a database. This all works fine.

Now, the user needs to edit those choices. I pull the data from the database, and display the relevant selections to the customer. Again, that same select multiple box, but this time with the previous selections highlighted. The customer changes the selection and submits it again.

This is the part I'm curious about. Right now, I take that input, plus the values from the database, and I build a hash. If the value is in the database *and* was submitted, I do nothing. If the value is in the database and not submitted, I delete it from the database. And lastly, if it was submitted but not in the database, I add it to the database.

My question is, is there a more efficient way to do this? Are there any tricks or php functions that can do this work easily? The code is fairly simple to do this, but I think I'm wasting a ton of memory because, in the end, I wind up with 3 lists that have roughly the same data depending on how many changes there were..

Any thoughts?

Share this post


Link to post
Share on other sites
A simpler solution, removing all the need for testing

Get the current values so you can display them
Delete all currentvalues from db
Let user change selection
Write new selection back to db

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.