我有两个表,user_info
和Friend_info
。当用户在user_info中更新他的记录时我想这样做,那么它也应该在friend_info中更新friend_id=user_id
。我试过这个
UPDATE user_info (name, user_email, Gender, DOB, contact, address) WHERE user_id='$user_id',
friends_info(name, user_email, Gender, DOB, contact, address) WHERE friend_id='$user_id'
values('$name', '$user_email', '$Gender', '$DOB', '$contact', '$address');
但它不起作用。请其他任何解决方案。不胜感激。
我知道这个问题为时已晚,现在问一下,但这是我的问题,因为我在做了这么多搜索之后感到很困惑,而且在我的情况下没有查询。
答案 0 :(得分:1)
你的问题不明确。所以你在phpmyadmin测试你想要查询的东西。如果没有那么你可能需要做一个交易。但是,如果它的测试或尝试这样:
UPDATE user_info (name, user_email, Gender, DOB, contact, address)
values('$name', '$user_email', '$Gender', '$DOB', '$contact', '$address')
WHERE user_id='$user_id';
UPDATE friends_info(name, user_email, Gender, DOB, contact, address)
values('$name', '$user_email', '$Gender', '$DOB', '$contact', '$address')
WHERE friend_id='$user_id';
所以这是两个查询,然后它们将一起执行。但现在用PHP
检查这些:
https://stackoverflow.com/a/802474/2226796
答案 1 :(得分:0)
您可以使用user_id作为连接键在语句中连接两个表。
UPDATE user_info ui
INNER JOIN friends_info fi
ON ui.user_id = fi.user_id
SET ui.name = $name,
SET ui.user_email = $email,
SET ui.Gender = $Gender,
SET ui.DOB = $DOB,
SET ui.contact = $contact,
SET ui.address = $address,
-- set friends_info
SET fi.name = $name,
SET fi.user_email = $email,
SET fi.Gender = $Gender,
SET fi.DOB = $DOB,
SET fi.contact = $contact,
SET fi.address = $address
WHERE ui.user_id = $user_id;