update two tables at once

前端 未结 2 1822
时光取名叫无心
时光取名叫无心 2021-01-05 23:31

I\'m using 5.1.41-3ubuntu12.10 for my MySQL version.

UPDATE profiledata SET aboutyou = \'$aboutyou\', quotes = \'$quotes\' 
WHERE uid = \'$sess_uid\'
         


        
相关标签:
2条回答
  • 2021-01-06 00:06

    MySQL does have multi-table update support: http://dev.mysql.com/doc/refman/5.0/en/update.html.

    UPDATE profiledata, profileprivacy 
    SET aboutYou = ..., aboutyouPrivacy = ... 
    WHERE (profiledata.uid = $sess_uid) OR (aboutyouPrivacy.uid = $sess_uid)
    

    or something similar should do the trick.

    0 讨论(0)
  • 2021-01-06 00:14

    You can use a join like this:

    $query = "UPDATE profiledata t1 
    JOIN profileprivacy t2 ON (t1.uid = t2.uid) 
    SET t1.aboutyou = '$aboutyou', 
        t1.quotes = '$quotes', 
        t2.aboutyouPrivacy = '$aboutyouPrivacy', 
        t2.quotesPrivacy = '$quotesPrivacy' 
    WHERE t1.uid = '$sess_uid'";
    
    0 讨论(0)
提交回复
热议问题