Jump to content


Photo

column value increment function


  • Please log in to reply
3 replies to this topic

#1 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 11 October 2006 - 08:02 AM

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
you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 11 October 2006 - 09:26 AM

Somthing like..


UPDATE table SET status = (status + 1) WHERE work_order = some_id;

Where...

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!



me!

#3 TEENFRONT

TEENFRONT
  • Members
  • PipPipPip
  • Advanced Member
  • 338 posts

Posted 11 October 2006 - 09:29 AM

set the colum value to auto increment ( do this in phpmyadmin when creating the columns ) and set the id as your primary key :)
Teenfront.co.uk : Free Teen Chat -  FunkySmileys.co.uk : MSN Smileys -  ArcadeMonkey.co.uk : Free Flash Games
8Baller.co.uk : Free Multiplayer Pool [url=http://8Baller.co.uk]

#4 paul2463

paul2463
  • Members
  • PipPipPip
  • Advanced Member
  • 955 posts
  • LocationUK

Posted 11 October 2006 - 09:30 AM

thanks printf

a one line function...love it
you cannot affect the past but you can ruin a perfectly good present by worrying about the future

*********************************************************************
The <A HREF="http://www.php.net/d...php">MANUAL</A> is actually a useful resource




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users