Jump to content


This topic is now archived and is closed to further replies.


column value increment function

Recommended Posts

Hello Guys.

a simple question for all you friendly people out there who know more than me, or I would not be asking the question I would be answering myself...

I am setting up a very very simple auditing page for out internal electronic workshop, it has a mysql table back end, this table has a few fields but one of them is the "status" field, when a job is taken into the workshop it is set to default "0", when work actually starts the status goes up to "1", when testing starts it goes up to "2" and so on until it is handed back to the user....so every day we can can print out the status of all jobs in the workshop.

I would like to write a simple function that updates the value of "status" by incrementing it by 1 when certain buttons are pressed, here is my idea
function updateStatus($id) {

increment value of status by 1 where id = $id


now for the question (got there eventually)

is there a sexy PHP/MySQL function to increment a table value by 1 or do i need to query the table to get the value, add 1 to it then update the table by setting the status field to the new value??

please be content that no animals will be hurt in the development of this function

Share this post

Link to post
Share on other sites
Somthing like..

[code]UPDATE table SET status = (status + 1) WHERE work_order = some_id;[/code]


work_order = would be changed to match your column name that identifies each row!
some_id = the id that identifies what row you want to update!


Share this post

Link to post
Share on other sites
set the colum value to auto increment ( do this in phpmyadmin when creating the columns ) and set the id as your primary key :)

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.