duancaishun4812 2011-03-01 04:21
浏览 88
已采纳

PHP如何设置脚本以从两个字段中获取两个数字值,然后添加它们并更新到第三个字段

I have a table with various fields 2 of which contain a number between 1 and 50.

I need help setting up a script that will automatically take two set fields add them and insert the total into a third field for each indivdual record for all records in the table.

I'm stuck in creating this because some records will have 0 or NULL values.

Please help :)

I've think I may be able to do this purely in SQL but the closest i found was this:

Alter table Mytable add column Keywords varchar(255);
update Mytable set Keywords = concat(Categories, ' ', Tags);

Obviously I would not need to add the column etc. Either a PHP or SQL solution would be fantastic.

Example in case I'mm not explaining this well it's confusing me a lot

Column 1 - Field Value: 20
Colum 2 - Field Value 20
Add Colum 1 + Colum 2 = 40
Insert 40 into Colum 3

Thanks

  • 写回答

4条回答 默认 最新

  • dongxiong5546 2011-03-01 04:28
    关注

    This should do it

    UPDATE [TABLE_NAME] SET col3 = [TABLE_NAME].col1 + [TABLE_NAME].col2;
    

    Replace [TABLE_NAME] and col1, col2, col3 with your tables and columns

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏