Php 如何使用数据库中的另一个表更新表记录?

Php 如何使用数据库中的另一个表更新表记录?,php,mysql,sql,Php,Mysql,Sql,表一:产品,其字段如下 products_id products_price master_categories_id 表二:特价商品。此表为空,其中的字段为 specials_id (an autoincrement field) products_id (the value same as table one) specials_new_products_price (the value equals products_price-(products_price*0.05)) speci

表一:
产品
,其字段如下

products_id
products_price
master_categories_id
表二:
特价商品
。此表为空,其中的字段为

specials_id (an  autoincrement field)
products_id (the value same as table one)
specials_new_products_price (the value equals products_price-(products_price*0.05))
specials_date_added (the value like this 2011-12-05 12:17:44)
specials_last_modified (the value like this  2011-12-05 12:19:10)
expires_date  (2011-12-31)
date_status_change  (the value like this 2011-12-05 12:19:10)
status  (1) 
specials_date_available  (2011-11-29)
现在,我想插入数据

("SELECT products_id,products_price FROM products where master_categories_id=79")
into table 2. and set the `status=1, specials_date_available=2011-11-29, 
expires_date=2011-12-31`.`products_id(the value same as table one)

specials_new_products_price (the value equals products_price-(products_price*0.05)) 
其余字段的值由您决定

按照我认为不好的方式,编写一个php文件来进行插入。选择产品id、产品价格,然后一行接一行地将其放入txt文件中,然后将文件内容放入表2中。但我不知道如何将文本文件数据放入表2中,以及如何设置rest字段值

insert into specials
(products_id, products_price,status,specials_date_available,expires_date)
SELECT products_id,products_price*0.95 as products_price,
 1, '2011-11-29', '2011-12-31'
FROM products where master_categories_id=79

或者类似的东西。

对不起,我不知道如何使用您的sql命令?以及如何设置这些字段的值specials\u date\u added date\u status\u change specials\u last\u modifiedSQL命令通常用于执行。当然你需要先弄清楚。好的,它将查询结果(包括文字值)作为名称列列表插入到specials中。现在我已经解释过了,我几乎无法为您理解:)但是在您的SQL命令中,您插入到specials表中的products\u price不是我想要的,我想要它的值等于products\u price-(products\u price*0.05)是的,抱歉,更改它,您的格式化程序非常混乱,我将编辑查询。我已经修改了查询,但一旦你想好了,你可以自己做:)