php/mysql question regarding editing related tables

This is a discussion on php/mysql question regarding editing related tables within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I am working on a form for editing and updating mysql data in several related tables like person, phoneNumber,and ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-26-2008
William Gill
 
Posts: n/a
Default php/mysql question regarding editing related tables

I am working on a form for editing and updating mysql data in several
related tables like person, phoneNumber,and e-mailAddress.

I need to display data from all three in order to know what records I am
editing, but I don't want to do updates on unchanged records (i.e. if
only phoneNumber changes, no need to update the other two).

simplistically I could do the following:

1 query all 3 tables
2 store data in hidden fields
3 display data
4 user edit
5 submit
6 compare original data to data in form fields to determine changes (or
use hasChanged flags)
7 update accordingly
8 go to 1

I'm curious what logical approach others have taken.
Reply With Quote
  #2 (permalink)  
Old 03-26-2008
Sylvain
 
Posts: n/a
Default Re: php/mysql question regarding editing related tables

William Gill wrote on 26/03/2008 15:33:
> I am working on a form for editing and updating mysql data in several
> related tables like person, phoneNumber,and e-mailAddress.
>
> I need to display data from all three in order to know what records I am
> editing, but I don't want to do updates on unchanged records (i.e. if
> only phoneNumber changes, no need to update the other two).
>
> simplistically I could do the following:
>
> 1 query all 3 tables


hope this means: one single request over joined tables

> 2 store data in hidden fields
> 3 display data
> 4 user edit
> 5 submit
> 6 compare original data to data in form fields to determine changes (or
> use hasChanged flags)
> 7 update accordingly


or update whatever changes.

the choice may depends on your server roles, it mysql & php run on the
same machine, php will have a persistant connexion to the base, in that
case you can let mysql decides (verifies) if update is actually needed.
if mysql server runs on a separate server and if the cost of request
forward is not null, check in php code if update(s) are required.

Sylvain.
Reply With Quote
  #3 (permalink)  
Old 03-26-2008
William Gill
 
Posts: n/a
Default Re: php/mysql question regarding editing related tables

Sylvain wrote:
> William Gill wrote on 26/03/2008 15:33:


>> 1 query all 3 tables

>
> hope this means: one single request over joined tables
>


Yes.

> or update whatever changes.
>
> the choice may depends on your server roles, it mysql & php run on the
> same machine, php will have a persistant connexion to the base, in that
> case you can let mysql decides (verifies) if update is actually needed.
> if mysql server runs on a separate server and if the cost of request
> forward is not null, check in php code if update(s) are required.


Please expound on letting MySQL decide. I thought if I issued an update
statement, it will update. I don't want unchanged records to get new
timestamps, and I don't think it efficient to update unnecessarily.

Are you saying do a comparison to see if data has changed in the WHERE
clause?

I'm not sure generically same server/ different server applies, but get
your point. If that becomes an issue I can change where the logic is
performed.
Reply With Quote
  #4 (permalink)  
Old 03-26-2008
Sylvain
 
Posts: n/a
Default Re: php/mysql question regarding editing related tables

William Gill wrote on 26/03/2008 16:39:
>
> Please expound on letting MySQL decide. I thought if I issued an update
> statement, it will update. I don't want unchanged records to get new
> timestamps, and I don't think it efficient to update unnecessarily.


I wasn't thinking about timestamps and yes they may be changed
unnecessarily.

I was thinking about performance issues only. Updating even with same
data one string field requires a quasi null time; the update of indexes,
if they exist, requires not null time; here I expect mysql to be smart
enough to not recompute indexes if the indexed data was not changed.

OOH, string comparison coded on php does not take a null time.

> Are you saying do a comparison to see if data has changed in the WHERE
> clause?


no, and I don't imagine a where clause to match that point.
a stored procedure can be a valuable intermediate solution:
performing the string comparison on typed mysql variables
will be (more or less) faster than in php code, conditional
update of the field within that stored procedure will take
benefit of the live connexion to the table.

Sylvain.
Reply With Quote
  #5 (permalink)  
Old 03-27-2008
larry@portcommodore.com
 
Posts: n/a
Default Re: php/mysql question regarding editing related tables

Keep your hidden values to a minimum, it will get messy keeping
original and working data as POST data.

Basically what I do:

1.Read in data
2.Store copy of data in a SESSION array
3.POST form of data, get input
4.validate
5.compare data with SESSION
6.UPDATE as needed


I guess you could also re-request old data from the DB before your
compare as well. Both of them keeps your POST form from being too
unwieldy.
Reply With Quote
Reply


Thread Tools
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:20 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0