Jump to content


Photo

Adding 1 to a number in a database


  • Please log in to reply
1 reply to this topic

#1 alexville

alexville
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 01 April 2006 - 01:31 AM

Hello,

I am making a php script. And I need help. I want to run a query where it grabs a number from the database then adds 1 to it. Could someone run me though this?

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 01 April 2006 - 01:56 AM

For incrementing and updating the row:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] table_name SET column_name = column_name + 1 WHERE some_column = 'something'
[!--sql2--][/div][!--sql3--]

For just selecting data and incrementing that value without updating existing row:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] column_name + 1 AS incremented_value FROM table_name WHERE some_column = 'something'
[!--sql2--][/div][!--sql3--]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users