mysql 增加row列_如何在mysql中將現有行的列的值加1 - How to add 1 to the value of a column of an existing row in mysql...

I have a table called pollData. It will always contain only 1 row. It has columns option1, option2, option3, option4, option5 each of type int. In the beginning, these columns have 0 as their value. How do I add 1 to any column, say option2? I mean do i retrieve the value of that column first, perform addition, and store back, or is there any auto increment function?

我有一個名為pollData的表。它總是只包含1行。它有列選項1,選項2,選項3,選項4,選項5,每個類型為int。在開始時,這些列的值為0。如何在任何列中添加1,比如option2?我的意思是我首先檢索該列的值,執行添加和存儲,還是有任何自動增量功能?

2 个解决方案

#1

31

You could try a normal UPDATE, and just replace the column option in question.

您可以嘗試正常的UPDATE,只需替換有問題的列選項。

UPDATE pollData SET option2 = option2 + 1

#2

1

Like this you can try :

像這樣你可以嘗試:

if(isset($option1)) {

$optadd = " option1 = option1+1";

} else if(isset($option2)) {

$optadd = " option2 = option2+1";

}

UPDATE `tablename` SET ".$optadd." WHERE fieldname = '1'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值