Suming MySQL existing number with varriable

时间:2015-06-25 18:14:38

标签: php mysql

I'm creating script which would sum number which is in database and the varriable - $currentPercent. But i can't find any topic where it explains how to do that. Here is my script part which only updates the existing value... So i ask again, how could i sum existing value and the $currentTasken varriable?

$inss = mysql_query("UPDATE dotp_tasks SET task_percent_complete = '$currentPercent' WHERE task_id='$currentTasken'") ;

UPDATED: For example $currentPercent is number 8. And the number in database is 82. And then sum it 90.

2 个答案:

答案 0 :(得分:2)

Hope this solves your problem:

$inss = mysql_query("UPDATE dotp_tasks 
SET task_percent_complete = task_percent_complete + '$currentPercent'
WHERE task_id='$currentTasken'") ;

But personally, I would suggest you to search more before asking these kind of questions

答案 1 :(得分:0)

Here you go try this: $inss = mysql_query("UPDATE dotp_tasks SET task_percent_complete=(select sum(A.task_percent_complete + '$currentPercent') from dotp_tasks A where A.task_id='$currentTasken') where task_id='$currentTasken'");