Re: [PHP] MySQL question...not sure if this is the correct forum to ask.

2002-02-16 Thread DL Neil

Luie,

> Wouldn't replace change all the entries in your table row, same effect as update?
> I believe the question is how to test which entry in a form has a new value and 
>replace/update only that value
in the table.
> If I have a form...
>
>  __
> |Employee Record Update|
> |  |
> |ID No:   1234 |
> |Name:_|
> |Address: _|
> |Status:  Married  |
> |  |
> |Submit|
>  --
>
> If I have this table...
>  _
> |idnonameaddressstatus|
> |-|
> |1234Peter45 street Single|
> |_|
>
> Which means I only want to replace the status and the name and address remains the 
>same.
> How do you test w/c entries in the form have new values and change only those 
>entries in the table?
>
> Peter, this is basically what your asking, right?
> I actually need to figure this one out myself so I would appreciate any info.


Do not use REPLACE if the table uses an AUTO_INCREMENT id, because if you do, any 
other tables linking into the
id column will need to be changed/become dislocated. Even if this is not the case, 
under these circumstances a
REPLACE is two db operations (DELETE followed by INSERT) and should be 'costed' 
accordingly.

In order to populate the form you must have first performed a SELECT to retrieve the 
data from the db. So from
there you can figure out what the data used to be - if you want/need to. You already 
have/send the existing data
values in/to the form (and can have it return form values as normal, and include the 
'original values' in
invisible fields - if you have to go that far).

When the form response comes back you have two choices:

1 PHP: use PHP to compare the ex-db values and the values returned from the form, then 
dynamically construct a
precise UPDATE statement (tailoring the SET clauses to the requisite column name and 
data value pairs). This is
a bit fiddly - and becomes more so as the number of form fields increases.

2 MySQL: use the intelligence of the MySQL UPDATE command (RTFM: MySQL only changes 
those values which need to
be changed) and issue a command which appears to UPDATE every possible-form-affected 
column (regardless of
whether is needs to be updated - according to 'form-thinking', because MySQL will 
decide for you and do the
'database-thinking')

Regards,
=dn


> >What about REPLACE?
> >
> >http://www.mysql.com/doc/R/E/REPLACE.html
> >
> >'REPLACE works exactly like INSERT, except that if an old record in the
> >table has the same value as a new record on a unique index, the old record
> >is deleted before the new record is inserted'
> >
>
> >>
> >> Hi,
> >>
> >> Can the UPDATE statement have conditional check embedded in it?  I
> >> have a page that displays a record (in a FORM format) that the user can
> >> change the information on each column.  I want to check each column and
> >> see which has been changed and update the table for entries that were
> >> changed only.
> >>
> >> for each column data {
> >>   if column is changed
> >>   then update;
> >>   else
> >>   do nothing;
> >> }
> >>
> >> Maybe I am making this too complicated than it needs and just go ahead
> >> and update all of the columns regardless with the new values, regardless
> >> they are actually different or not.
> >>
> >> Thanks in advance,
> >> -Peter



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: [PHP] MySQL question...not sure if this is the correct forum to ask.

2002-02-15 Thread Luie


Wouldn't replace change all the entries in your table row, same effect as update?
I believe the question is how to test which entry in a form has a new value and 
replace/update only that value in the table.
If I have a form...

 __
|Employee Record Update|
|  |  
|ID No:   1234 |  
|Name:_|
|Address: _|
|Status:  Married  | 
|  |  
|Submit|
 --  

If I have this table...
 _
|idnonameaddressstatus|
|-|
|1234Peter45 street Single|
|_|

Which means I only want to replace the status and the name and address remains the 
same.
How do you test w/c entries in the form have new values and change only those entries 
in the table?
  
Peter, this is basically what your asking, right?
I actually need to figure this one out myself so I would appreciate any info.

thanks...

luie


>What about REPLACE?
>
>http://www.mysql.com/doc/R/E/REPLACE.html
>
>'REPLACE works exactly like INSERT, except that if an old record in the
>table has the same value as a new record on a unique index, the old record
>is deleted before the new record is inserted'
>

>>
>> Hi,
>>
>> Can the UPDATE statement have conditional check embedded in it?  I
>> have a page that displays a record (in a FORM format) that the user can
>> change the information on each column.  I want to check each column and
>> see which has been changed and update the table for entries that were
>> changed only.
>>
>> for each column data {
>>   if column is changed
>>   then update;
>>   else
>>   do nothing;
>> }
>>
>> Maybe I am making this too complicated than it needs and just go ahead
>> and update all of the columns regardless with the new values, regardless
>> they are actually different or not.
>>
>> Thanks in advance,
>> -Peter


__
www.edsamail.com

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: [PHP] MySQL question...not sure if this is the correct forum to ask.

2002-02-14 Thread Daniel Rosher

What about REPLACE?

http://www.mysql.com/doc/R/E/REPLACE.html

'REPLACE works exactly like INSERT, except that if an old record in the
table has the same value as a new record on a unique index, the old record
is deleted before the new record is inserted'

Regards,
Dan

> -Original Message-
> From: Rick Emery [mailto:[EMAIL PROTECTED]]
> Sent: Friday, 15 February 2002 11:10 a.m.
> To: [EMAIL PROTECTED]
> Cc: '[EMAIL PROTECTED]'
> Subject: FW: [PHP] MySQL question...not sure if this is the correct
> forum to ask.
>
>
> -Original Message-
> From: Peter Ruan [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 14, 2002 4:04 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] MySQL question...not sure if this is the correct forum to
> ask.
>
>
> Hi,
>
> Can the UPDATE statement have conditional check embedded in it?  I
> have a page that displays a record (in a FORM format) that the user can
> change the information on each column.  I want to check each column and
> see which has been changed and update the table for entries that were
> changed only.
>
> for each column data {
>   if column is changed
>   then update;
>   else
>   do nothing;
> }
>
> Maybe I am making this too complicated than it needs and just go ahead
> and update all of the columns regardless with the new values, regardless
> they are actually different or not.
>
> Thanks in advance,
> -Peter
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> -
> Before posting, please check:
>http://www.mysql.com/manual.php   (the manual)
>http://lists.mysql.com/   (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
> <[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>
>


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




FW: [PHP] MySQL question...not sure if this is the correct forum to ask.

2002-02-14 Thread Rick Emery

-Original Message-
From: Peter Ruan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 14, 2002 4:04 PM
To: [EMAIL PROTECTED]
Subject: [PHP] MySQL question...not sure if this is the correct forum to
ask.


Hi,

Can the UPDATE statement have conditional check embedded in it?  I
have a page that displays a record (in a FORM format) that the user can
change the information on each column.  I want to check each column and
see which has been changed and update the table for entries that were
changed only.

for each column data {
  if column is changed
  then update;
  else
  do nothing;
}

Maybe I am making this too complicated than it needs and just go ahead
and update all of the columns regardless with the new values, regardless
they are actually different or not.

Thanks in advance,
-Peter




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php