for loop update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The structure of the update statement is simply wrong.
You cannot combine different UPDATEs this way ... no way.

It wouldn't make sense anyway
WHERE
(FIRST_NAME='bob' ...)
AND (FIRST_NAME='bob2' ...)
AND (FIRST_NAME='bob3' ...)
how could FIRST_NAME be eqault to bob AND eqault to bob2 AND eqault to bob3 at the same time/record?
tam2000k2
Forum Newbie
Posts: 13
Joined: Mon Jul 31, 2006 2:08 pm

Post by tam2000k2 »

You are correct, it was the paren. However, here is the SQL string that doesn't seem to be operating properly. Yet there are no errors reported.


Code: Select all

UPDATE guest_login SET FIRST_NAME= 'bob2', LAST_NAME= 'newhart', EMAIL_ADDRESS= 'bob@newhart.com', WHAT_U_LIKED= 'yes' AND FIRST_NAME= 'bob3', LAST_NAME= 'newhart', EMAIL_ADDRESS= 'bob2@newhart.com', WHAT_U_LIKED= 'yes2' AND FIRST_NAME= 'bob4', LAST_NAME= 'newhart', EMAIL_ADDRESS= 'bob3@newhart.com', WHAT_U_LIKED= 'yes' WHERE (FIRST_NAME='bob' AND LAST_NAME= 'newhart' AND EMAIL_ADDRESS='bob@newhart.com' AND WHAT_U_LIKED='yes') AND (FIRST_NAME='bob2' AND LAST_NAME= 'newhart' AND EMAIL_ADDRESS='bob2@newhart.com' AND WHAT_U_LIKED='yes2') AND (FIRST_NAME='bob3' AND LAST_NAME= 'newhart' AND EMAIL_ADDRESS='bob3@newhart.com' AND WHAT_U_LIKED='yes')
Why is this not working? I guess I have to retrieve the ID which is the unique identifier to make this work. I can do a single update with no problem but multiple rows updates have yet to be successful, but it seems like such an easy process in theory.

Hopefully the last time but thanks in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How many times do we have to say this?

You cannot update multiple records will differing data with the same update query in the manor you wish.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

UPDATE  `guest_login` 
    SET     `FIRST_NAME`= 'bob2' ,
            `LAST_NAME` = 'newhart', 
            `EMAIL_ADDRESS` = 'bob@newhart.com', 
            `WHAT_U_LIKED` = 'yes'
WHERE   `FIRST_NAME` = 'bob'
        `LAST_NAME` = 'newhart'
        `EMAIL_ADDRESS` = 'bob@newhart.com'
        `WHAT_U_LIKED` ='yes' 

Code: Select all

UPDATE  `guest_login` 
    SET     `FIRST_NAME` = 'bob3'    
            `LAST_NAME` = 'newhart'
            `EMAIL_ADDRESS` = 'bob2@newhart.com'
            `WHAT_U_LIKED` = 'yes2'
WHERE   `FIRST_NAME` = 'bob2'
        `LAST_NAME` = 'newhart'
        `EMAIL_ADDRESS` = 'bob2@newhart.com'
        `WHAT_U_LIKED`= 'yes2'

Code: Select all

UPDATE  `guest_login` 
    SET     `FIRST_NAME` = 'bob4',
            `LAST_NAME` = 'newhart'
            `EMAIL_ADDRESS` = 'bob3@newhart.com'
            `WHAT_U_LIKED` = 'yes'
WHERE   `FIRST_NAME` = 'bob3'
        `LAST_NAME` = 'newhart' 
        `EMAIL_ADDRESS` = 'bob3@newhart.com' 
        `WHAT_U_LIKED` = 'yes'
3 updates, 3 queries.
Post Reply