duanhuoyao7011 2015-01-18 10:43
浏览 105
已采纳

如何在yii2中为sql表的现有值添加值?

I have created a stock module in yii2. Using gii functionality I can add products to table. But what to do when product already exists in the table and new quantity needs to be added to existing quantity leaving total quantity in db. For example,

Products

Quantity

5

I need to update Quantity by any value for example '5+3', leaving other fields of sql table unchanged.

need output like below

Quantity

8

How do I update my controller to do that? And of course I want to be able to do it in create action.

  • 写回答

1条回答 默认 最新

  • dqf60304 2015-01-18 22:01
    关注

    Here are the steps you should follow:

    1. Figure out how you identify if a product already exists. Based on what? name? internal code? etc.
    2. When you create a product search the db to see if that product already exists based on your criteria.
    3. Decide what you do with the extra data, what if the product is already there based on the code but the name has changed.
    4. If it does exist then update the quantity.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题