Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中基于另一个表更新mysql表_Php_Mysql_Ajax - Fatal编程技术网

如何在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、 城市更新=城市名称