Go Back   Garayed.com > PHP
Reply
 
LinkBack Thread Tools Search this Thread Display Modes

updating only when data is different
  #1 (permalink)  
Old 07-03-2009, 02:43 AM
student4life
 
Posts: n/a
Default updating only when data is different

Hello,

If I have self-submitting page that will have the data fields
refreshed/updated ONLY when the data are different between each
submission, could someone show me what the best way is to accomplish
this task? I was thinking using $_SESSION variable and compare the
stored value to that of the $_REQUEST variable and proceed with
database operations only when there is a difference. TIA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: updating only when data is different
  #2 (permalink)  
Old 07-03-2009, 06:34 AM
jeff
 
Posts: n/a
Default Re: updating only when data is different

student4life wrote:
> Hello,
>
> If I have self-submitting page that will have the data fields
> refreshed/updated ONLY when the data are different between each
> submission,


I have to ask, what does it matter? If the data is the same, what
would it matter if it were overwritten. It's no less trouble to select
and compare than to just update. MySQL has REPLACE.

I assume there is something else?

Jeff


could someone show me what the best way is to accomplish
> this task? I was thinking using $_SESSION variable and compare the
> stored value to that of the $_REQUEST variable and proceed with
> database operations only when there is a difference. TIA

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: updating only when data is different
  #3 (permalink)  
Old 07-03-2009, 12:29 PM
C. (http://symcbean.blogspot.com/)
 
Posts: n/a
Default Re: updating only when data is different

On Jul 3, 2:43*am, student4life <student4li...@gmail.com> wrote:
> Hello,
>
> * If I have self-submitting page that will have the data fields
> refreshed/updated ONLY when the data *are different between each
> submission, could someone show me what the best way is to accomplish
> this task? I was thinking using $_SESSION variable and compare the
> stored value to that of the $_REQUEST variable and proceed with
> database operations only when there is a difference. TIA


So the form submits itself but between times the user might have
changed something.

If you use a session then YOU ARE UPDATING THE (session) DATA EVERY
TIME ANYWAY.

I think the your objective is decidedly dubious, and your proposed
solution is innappropriate as per above. Assuming that your objective
is valid, then you could acheive it by including the original values
in one or more hidden form fields. This does make possible CSRF issues
would could be avoided by adding additional checks, e.g.

<?php
$prev=$_REQUEST['prev'];
unset($_REQUEST['prev'];
$payload_chk=sha1(var_export($_REQUEST,true) . "s3cr3t"));
if ($payload!=$prev) {
update_date($_REQUEST); // data has changed
}
print "<form method='POST'>";
$payload_chk=sha1(var_export($_REQUEST,true) . "s3cr3t"));
print "<input type=='hidden' name='prev' value='$old'>";
.....show rest of form

C.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: updating only when data is different
  #4 (permalink)  
Old 07-03-2009, 01:44 PM
Jerry Stuckle
 
Posts: n/a
Default Re: updating only when data is different

student4life wrote:
> Hello,
>
> If I have self-submitting page that will have the data fields
> refreshed/updated ONLY when the data are different between each
> submission, could someone show me what the best way is to accomplish
> this task? I was thinking using $_SESSION variable and compare the
> stored value to that of the $_REQUEST variable and proceed with
> database operations only when there is a difference. TIA


What's the purpose you are trying to achieve? And where do you want to
update the data? Screen? Database? Mars? (Forget the last one :-) ).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: updating only when data is different
  #5 (permalink)  
Old 07-06-2009, 06:45 PM
student4life
 
Posts: n/a
Default Re: updating only when data is different

On Jul 3, 7:29*am, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.com> wrote:
> On Jul 3, 2:43*am, student4life <student4li...@gmail.com> wrote:
>
> > Hello,

>
> > * If I have self-submitting page that will have the data fields
> > refreshed/updated ONLY when the data *are different between each
> > submission, could someone show me what the best way is to accomplish
> > this task? I was thinking using $_SESSION variable and compare the
> > stored value to that of the $_REQUEST variable and proceed with
> > database operations only when there is a difference. TIA

>
> So the form submits itself but between times the user might have
> changed something.
>
> If you use a session then YOU ARE UPDATING THE (session) DATA EVERY
> TIME ANYWAY.
>
> I think the your objective is decidedly dubious, and your proposed
> solution is innappropriate as per above. Assuming that your objective
> is valid, then you could acheive it by including the original values
> in one or more hidden form fields. This does make possible CSRF issues
> would could be avoided by adding additional checks, e.g.
>
> <?php
> $prev=$_REQUEST['prev'];
> unset($_REQUEST['prev'];
> $payload_chk=sha1(var_export($_REQUEST,true) . "s3cr3t"));
> if ($payload!=$prev) {
> * update_date($_REQUEST); // data has changed}
>
> print "<form method='POST'>";
> $payload_chk=sha1(var_export($_REQUEST,true) . "s3cr3t"));
> print "<input type=='hidden' name='prev' value='$old'>";
> ....show rest of form
>
> C.


This current task I do is trivial so I can just do insert/replace to
refresh the data for every request but I was just wondering for
scenario that requires more costly database operations there would
probably be a way to minimize the cost. You indicated that the value
needs to be stored/updated every time in $_SESSION (or temporary
variable) anyway but the way I see is that it's going to be stored/
updated only when it's different from the value in $_REQUEST, no? I
guess what it boils down to is the cost of database operations versus
the cost of persisting objects in the sessions for PHP, in single and
multi-user environments and I was curious to see what the current best
practices are. Maybe someone will see the need for persistent layer
and create one for php too just like Hibernate/TopLink was geared for
Java.

Thanks all for your responses.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: updating only when data is different
  #6 (permalink)  
Old 07-06-2009, 07:38 PM
Mason Barge
 
Posts: n/a
Default Re: updating only when data is different

On Thu, 2 Jul 2009 18:43:38 -0700 (PDT), student4life <student4lifer@gmail.com> wrote:

>Hello,
>
> If I have self-submitting page that will have the data fields
>refreshed/updated ONLY when the data are different between each
>submission, could someone show me what the best way is to accomplish
>this task? I was thinking using $_SESSION variable and compare the
>stored value to that of the $_REQUEST variable and proceed with
>database operations only when there is a difference. TIA


Your proposed solution sounds simple enough to me, only I'd use the specific method (probably $_POST) instead of
REQUEST.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: updating only when data is different
  #7 (permalink)  
Old 07-06-2009, 10:42 PM
Gordon Burditt
 
Posts: n/a
Default Re: updating only when data is different

>This current task I do is trivial so I can just do insert/replace to
>refresh the data for every request but I was just wondering for
>scenario that requires more costly database operations there would
>probably be a way to minimize the cost.


The database is likely to avoid writes if the data hasn't changed.

>You indicated that the value
>needs to be stored/updated every time in $_SESSION (or temporary
>variable) anyway but the way I see is that it's going to be stored/
>updated only when it's different from the value in $_REQUEST, no? I


As I understand the way alternate session save handlers work, if
you've got a session, the session data will be saved at the end of
processing the page. No conditions. The value of anything in
$_REQUEST has nothing to do with it.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:42 AM.


Powered by vBulletin® Version 3.5.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
| Home | FAQ | Members List | Calendar | Today's Posts | Search | New Posts |