This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating fields  RSS feed

 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

I am working on a method for updating user details. The user can update *upto* 10 fields. The problem is how do I accomadate this whilst coding the method ? Is there a way I can ONLY update the fields the user has modified and leave the rest intact ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your post is amazingly lacking in any details that would be needed to adequately address the question.

What, for example, type of "fields" are you talking about? DB? HTML? Strawberry? Other?
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Lets say i have, firstname, lastname, email, dob, address1, address2 etc
All of these fields were filled in on user registration but now the user wants to change the address1 and email, and maybe sometime later he changes other details in his profile.
 
Paul Clapham
Sheriff
Posts: 22531
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So your process is like this:

1. You get those data items from a database (let's guess).

2. You send them in some HTML to be displayed in a form on the browser.

3. The user changes some of them and clicks on the button to submit that form.

4. You get the data from the form and update the data items in the database.

And your question is, if the user didn't change (let's say) his last name, you don't want to update that column of the database? Right? Then my question is, why not?
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul , what might be the solution for this . Could you please post the idea how to accomplish this ?
 
Bosun Bello
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not much info in your request, however if what Paul said is your plan, yu can either update the fields, changed or not. Or you have to compare the fields to the one in the backend to see if they are the same, and if so, do not update the database.
 
Paul Clapham
Sheriff
Posts: 22531
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that may be true, but the effect of asking whether the last-name field is "maff", and if it is, leaving it that way, and if it isn't, updating it to be "maff", is the same as the effect of just updating it to be "maff". Only it's a lot messier to do that. That's why I asked what the point of the question was.

If the user clicked "OK" on a form which says FirstName="shaf" and LastName="maff", then the most straightforward thing to do would be to write those values to the database. That was what the user wanted when he or she clicked "OK". Why would you do anything else?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please dont think that checking first is somehow "more efficient" or "better performing" - thats the kind of premature optimization that gets people in trouble as the code gets more and more complicated.

Go for simplicity and easy to understand/document code first.

Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!