doudichu1358 2017-11-29 13:03
浏览 50
已采纳

更新id等于3的表,并在updatecount列中的已存在值中添加加1

I am attempting to update a table where its id is equal 3 and to increase a column called updatecount for example if the value in the column was 3 let it add one and make it 4. Here is my table structure

Images

id | photo | updatecount |
1     xyz  |   3

If I update the photo again where id is equal to 1 then the result becomes

id | photo | updatecount |
1     xyz  |   4

Here is my controller definition

public function upDateAction(Request $request)
    {
      $intid = (int)$request->request->get('imageid'); //convert the request object to int
$image = new Image();
... //to do updating here

EDITTED

Here is my model >>>

/**
     * @var string
     *
     * @ORM\Column(name="photo", type="string", length=255, nullable=true)
     */
    private $photo;

    /**
     * @var integer
     *
     * @ORM\Column(name="updatecount", type="integer", nullable=true)
     */
    private $updatecount;
  • 写回答

1条回答 默认 最新

  • dqppv86022 2017-11-29 13:15
    关注

    Hope this should do the required job

    public function upVoteAction(Request $request)
    {
        $intid = (int)$request->request->get('imageid'); //convert the request object to int
        $em = $this->getContainer()->get('doctrine')->getManager();
        $image = $em->getRepository('YourBundle:Image')->find($intid);
        $image->setUpdatecount($image->getUpdatecount() + 1);
        $em->persist($image);
        $em->flush();
    }
    

    First get your image object from repository getRepository() using the image id. Then set updatecount as setUpdatecount() by increment in existing value

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?