mizako 0 Report post Posted July 16, 2005 Hi,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. Share this post Link to post Share on other sites
SystemWisdom 0 Report post Posted July 17, 2005 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: UPDATE MyTable SET MyColumn=MyColumn+1 Where MyID=123 Put that in a string and pass it to MySQL... I hope that helps! Share this post Link to post Share on other sites
hype 0 Report post Posted July 17, 2005 I believe you can easily do that by going to your phpmyadmin and configurate the auto-increment fields and it'll make it a column there itself... Share this post Link to post Share on other sites
SystemWisdom 0 Report post Posted July 17, 2005 Auto-increment only works for insert statements, as it gives the next row a new ID number, but all previous rows will remain unaffected.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... Share this post Link to post Share on other sites
mizako 0 Report post Posted July 18, 2005 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: UPDATE MyTable SET MyColumn=MyColumn+1 Where MyID=123 Put that in a string and pass it to MySQL... I hope that helps! 162207[/snapback] Thanks that was the solution i was looking for!! Share this post Link to post Share on other sites
BuffaloHelp 24 Report post Posted July 18, 2005 Question answered: topic closed. Share this post Link to post Share on other sites
iGuest 3 Report post Posted February 25, 2008 can i display upcoming row id in my form and can later fill all the information 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 Share this post Link to post Share on other sites
iGuest 3 Report post Posted August 5, 2008 auto incement 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 (Xisto.com) Share this post Link to post Share on other sites
iGuest 3 Report post Posted November 4, 2009 Increment A Mysql Column - how to increment a MySQL column with some input value.Increment A Mysql Columnhi, 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 Share this post Link to post Share on other sites
iGuest 3 Report post Posted April 25, 2010 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 Share this post Link to post Share on other sites
iGuest 3 Report post Posted April 25, 2010 my answerIncrement A Mysql ColumnI 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 Share this post Link to post Share on other sites