Jump to content


Photo

Algorithm Question


  • Please log in to reply
1 reply to this topic

#1 XenoPhage

XenoPhage
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts

Posted 09 March 2006 - 04:18 PM

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?
--
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 09 March 2006 - 09:46 PM

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users