【问题标题】:How to update mysql table in PHP on the basis of another table如何在另一个表的基础上更新PHP中的mysql表
【发布时间】:2023-04-10 23:39:01
【问题描述】:

我的数据库中有以下表格:

餐桌顺序

|------------------------------------------------------|
| 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_id = ‘$city_id’; $城市名称[城市名称];

终于要更新下订单表了

Update `order` SET ` City_to_be_update`= $city_name’;

如何做到这一点,请任何人帮助我?

【问题讨论】:

    标签: php mysql ajax


    【解决方案1】:

    试试这个带有连接的查询,

        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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-09
      • 2021-02-21
      • 1970-01-01
      • 2013-01-26
      • 2020-06-26
      • 2013-08-15
      • 1970-01-01
      相关资源
      最近更新 更多