|
|
Increment A Mysql Column - how to increment a MySQL column one unit | ||
Discussion by mizako with 10 Replies.
Last Update: April 25, 2010, 10:14 am ( View Rated (4) ) | |||
![]() |
|
|
I have a column in a MySQL table which contains a counter of the views of the object described by this table. I would like to increment this value by one everytime the object is viewed. Obviously came into my mind the possibility of retrieving the value of this field, store it in a variable increment this value by one and perform an UPDATE query again with this new value. My question is if there is a MySQL option to update the field with its actual value plus an unit increment. I hope you understand the issue.
CODE
UPDATE MyTable SET MyColumn=MyColumn+1 Where MyID=123
Put that in a string and pass it to MySQL... I hope that helps!
He wants to update an existing row (via code) and increment any one of the columns in it, thus the simple update statement I posted above would work fine for this purpose...
QUOTE (SystemWisdom)
What you are trying to achieve can be done in a single SQL statement without the need to return any records... In fact, 1 simple update statement like:CODE
UPDATE MyTable SET MyColumn=MyColumn+1 Where MyID=123
Put that in a string and pass it to MySQL... I hope that helps!
Thanks that was the solution i was looking for!!
Increment A Mysql Column
Hello all,
I want to display the upcoming record no which is autoincrement and when I open add form for fill data, id of that row I want to display and later I want to fill rest of the record. So is there any function in php so I can show this.
-question by Yogendra Mishra
Increment A Mysql Column
How can I implement autoincrement in mysql?
Please explain with one example.
-question by RamManohar Nukala
admin reply
You have to set the property of column as AUTO-INCREMENT. And then feel NULL to it, it will take the NEXT value.
-Shree (Trap17.com)
hi,
I want to increment my mysql column with an input 'x'.
Wil UPDATE EMPLOYEE SET points=points+x be a solution?
My doubt is wheather I can increment the column directly using the variable x or need to use '%d' (or %s ?...Total confusion..!!)?
what should be tha datatype of x?
Also
sprintf(Query,"INSERT INTO category(ID,Cat,CatID) VALUES(NULL,'%s',%d)", newCatName, atoi(newCatID));
here,when I want to display the CatID field, a '%s' ( taking it as a string) wil do?
Since I am trying to learn through websites,I want somebodies help.Please Help.
Thank You Very Much.
-question by Aswathy
I was looking for this - hope it helps somebody - works fine in mysql
SET @pos =0;UPDATE players SET row_id = ( SELECT @pos := @pos +1
-reply by alextoader
I was looking for this - hope it helps somebody - works fine in mysql
SET @pos =0;UPDATE players SET row_id = ( SELECT @pos := @pos +1 );
-reply by alextoader
Similar Topics:
Best Php And Mysql Editor For Noobs
Tokens In C++ Explained
How To Put An Active Shoutbox On Yo...
Write Random Text To Image PHP script help! (5)
|
(3) Getting Errors On A Script need to know what im doing wrong
|
Loading...
HOME 






