如何在PHP中基于另一个表更新mysql表
我的数据库中有以下表格: 表顺序如何在PHP中基于另一个表更新mysql表,php,mysql,ajax,Php,Mysql,Ajax,我的数据库中有以下表格: 表顺序 |------------------------------------------------------| | Id | uid | order | price | City_to_be_update |------------------------------------------------------| | 1 | 25 | someFoods | 10025 | |------------------------
|------------------------------------------------------|
| Id | uid | order | price | City_to_be_update
|------------------------------------------------------|
| 1 | 25 | someFoods | 10025 |
|------------------------------------------------------|
| 2 | 30 |Some veggies| 2015|
|------------------------------------------------------|
| 3 | 12 |Milk | 145 |
|------------------------------------------------------|
表格用户:
|------------------------------------------------|
| Id | uid | city_id | Address|
|------------------------------------------------|
| 1 | 30 | 1 | myAddress |
|------------------------------------------------|
| 2 | 12 | 2 | Asdfads |
|------------------------------------------------|
| .... | .. | .. | ....... |
|------------------------------------------------|
表城市:
|------------------------------------------------|
| Id |city_id| city_name | Country|
|------------------------------------------------|
| 1 | 2 | Abc | Uae |
|------------------------------------------------|
| 2 | 3 | Def | Ghi |
|------------------------------------------------|
| .... | .. | .. | ....... |
|------------------------------------------------|
我想做的是
Select * from `order`
$user_id [ uid ];
Select * from `users` where `uid` = ‘$user_id’;
$city_id [ city_id ];
从city
中选择*其中city\u id
=“$city\u id”;
$city_name[城市名称]
最后要更新订单表,如下所示
Update `order` SET ` City_to_be_update`= $city_name’;
如何执行此操作,请有人能帮助我吗?尝试使用连接进行此查询
UPDATE
< OrderTable > AS a LEFT JOIN < UsersTable > AS b ON a.uid=b.uid
LEFT JOIN < CityTable > AS c ON b.city_id=c.city_id
SET
a.City_to_be_update=c.city_name
更新
作为左连接作为a.uid=b.uid上的b
左连接作为b.city\u id=c.city\u id上的c
设置
a、 城市更新=城市名称