Incrementing value in column (1 Viewer)

dyouss

New member
Local time
Today, 11:33
Joined
Jan 27, 2007
Messages
1
Hello,

I want to increment the value stored in a column everytime someone clicks on buttons (one row per button).

I can think of one way of doing this: retrieve the value from database (eg: 43), add 1 and return the value to the database (ie, 44). However, I was wondering if there was an easier way.

Also, what happens if there is no record in the table (eg: the first time a button is clicked)?

Thanks!

Dima
 

rich2600

Total access newb.
Local time
Today, 08:33
Joined
Mar 12, 2007
Messages
10
Hello,

I want to increment the value stored in a column everytime someone clicks on buttons (one row per button).

I can think of one way of doing this: retrieve the value from database (eg: 43), add 1 and return the value to the database (ie, 44). However, I was wondering if there was an easier way.

Also, what happens if there is no record in the table (eg: the first time a button is clicked)?

Thanks!

Dima

Unfortunately, i could not think of anything that would be more simplistic than just incrementing ontop of database values, but regarding the first time a button is clicked, just set a default value upon making the table.

Ex. value int(11) default '0',

also, if you wanted to store other user data along with the incrementing value of the button clicked, you could tack on the IP and Browser type, and just auto_increment the primary key. Allowing you to show which user and who was the one that clicked that button on value "444" and keep a detailed record.
 

Users who are viewing this thread

Top Bottom