简体   繁体   English

使用来自不同表中另一行的数据更新单行或多行

[英]Update single or multiple row with data from another row in the different table

Admin need to approve profile information only then it will be displayed. 管理员只需要批准个人资料信息,它就会显示出来。 For this my thought is we need to store the data in a dummy table and after reviewing it by the admin and approves it the data update occurs in the master user table. 为此,我的想法是我们需要将数据存储在虚拟表中,并在由管理员查看并批准数据后在主用户表中进行数据更新。

So I need to update the master table row using the dummy table row. 因此,我需要使用虚拟表行更新主表行。 How to do it using simple update query? 如何使用简单的更新查询呢?

Is there any other simpler method? 还有其他更简单的方法吗?

I doing it using PHP MySQL 我用PHP MySQL做

You can insert it to the table like (if both tables are alike): 您可以将其插入到表中(如果两个表都相同):

INSERT INTO MasterTable
  SELECT * FROM DummyTable

A suggestion from my side: 我这边的建议:

You can add a boolean column to the MasterTable like IsApproved . 您可以像IsApproved一样向MasterTable添加一个布尔列。 And set it to false by default. 并将其默认设置为false

When selecting records from it, use: 从中选择记录时,请使用:

SELECT * FROM MasterTable WHERE IsApproved='true'

So users will not get those records which are not approved. 因此,用户将不会获得未批准的记录。 When administrator approves each record, update that record and set IsApproved to true . 当管理员批准每个记录时,请更新该记录并将IsApproved设置为true ie,

UPDATE MasterTable
SET IsApproved='true'
Where ID=ItsID

So, now user user will be able to get that record. 这样,现在用户user就能获得该记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM