Loading...


bookmark - Increment A Mysql Column how to increment a MySQL column one unit

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) )
 
bookmark - Increment A Mysql Column how to increment a MySQL column one unit  
Quickly Post to Increment A Mysql Column how to increment a MySQL column one unit w/o signup Share Info about Increment A Mysql Column how to increment a MySQL column one unit using Facebook, Twitter etc. email your friend about Increment A Mysql Column how to increment a MySQL column one unit Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

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.







   Sat Jul 16, 2005    Reply         

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!

   Sat Jul 16, 2005    Reply         

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...

   Sun Jul 17, 2005    Reply         


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...

   Sun Jul 17, 2005    Reply         

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!!








   Sun Jul 17, 2005    Reply         

Question answered: topic closed.

   Sun Jul 17, 2005    Reply         


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

   Sun Feb 24, 2008    Reply         

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 (Trap17.com)

   Tue Aug 5, 2008    Reply         

Increment A Mysql Column - how to increment a MySQL column with some input value.Increment A Mysql Column

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

   Tue Nov 3, 2009    Reply         

my answerIncrement A Mysql Column

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

 

   Sun Apr 25, 2010    Reply         

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

 

   Sun Apr 25, 2010    Reply         

Quickly Post to Increment A Mysql Column how to increment a MySQL column one unit w/o signup Share Info about Increment A Mysql Column how to increment a MySQL column one unit using Facebook, Twitter etc. email your friend about Increment A Mysql Column how to increment a MySQL column one unit Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

Best Php And Mysql Editor For Noobs

hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness ...more

   06-May-2008    Reply         

Tokens In C++ Explained

Earlier I was writing this for my website but now I am sharing this with you guys so that who are either new to c++ or learning c++ can get some benefits. Hey mods this is my original work and I haven't copied this from any website. Tokens The smallest in ...more

   31-Aug-2009    Reply         

How To Put An Active Shoutbox On Yo...

Hi, In this tutorial I will cover the simple concept of making a global shoutbox in a website. This tutorial covers basics and some nice features. Let's go over the method we have in mind first, so you're not completely lost when doing this for yourself. ...more

   06-Apr-2010    Reply         

Write Random Text To Image PHP script help!   Write Random Text To Image PHP script help! (5) (3) Getting Errors On A Script need to know what im doing wrong  Getting Errors On A Script need to know what im doing wrong