Welcome Guest ( Log In | Register)



 
Closed TopicStart new topic
> Increment A Mysql Column, how to increment a MySQL column one unit
mizako
post Jul 16 2005, 11:10 PM
Post #1


Super Member
*********

Group: Members
Posts: 372
Joined: 16-August 04
From: Spain
Member No.: 824



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.
Go to the top of the page
 
+Quote Post
SystemWisdom
post Jul 17 2005, 12:13 AM
Post #2


Advanced Member
*******

Group: Members
Posts: 117
Joined: 3-May 05
From: A Canadian South of the 49th Parallel
Member No.: 6,544



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!
Go to the top of the page
 
+Quote Post
hype
post Jul 17 2005, 08:44 AM
Post #3


Legend Killer
*********

Group: Members
Posts: 678
Joined: 15-April 05
From: Singapore
Member No.: 5,697



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...
Go to the top of the page
 
+Quote Post
SystemWisdom
post Jul 17 2005, 01:57 PM
Post #4


Advanced Member
*******

Group: Members
Posts: 117
Joined: 3-May 05
From: A Canadian South of the 49th Parallel
Member No.: 6,544



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...
Go to the top of the page
 
+Quote Post
mizako
post Jul 18 2005, 05:41 AM
Post #5


Super Member
*********

Group: Members
Posts: 372
Joined: 16-August 04
From: Spain
Member No.: 824



QUOTE(SystemWisdom @ Jul 17 2005, 12:13 AM)
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!!
Go to the top of the page
 
+Quote Post
BuffaloHELP
post Jul 18 2005, 05:51 AM
Post #6


Desperately seeking "any key" to continue...
Group Icon

Group: Admin
Posts: 3,434
Joined: 23-April 05
From: Trap17 storage box
Member No.: 6,042



Question answered: topic closed.
Go to the top of the page
 
+Quote Post
iGuest
post Feb 25 2008, 07:28 AM
Post #7


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



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
Go to the top of the page
 
+Quote Post

Closed TopicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Problem On Mysql "order By"(5)
  2. Can Reset The Id Auto Increment?(10)
  3. Can You Add Images Into A Mysql Database?(20)
  4. Creating Profiles In Php/mysql ?(7)
  5. Php Search Engine Script For Mysql Database(11)
  6. Editing Information In A Mysql Database And Deleting Rows(5)
  7. Putting Data Of 2 Pages In Mysql At Once(1)
  8. Mysql Query(2)
  9. Simple Mysql Query Limiting(9)
  10. Some Mysql Basics(4)
  11. Php, Mysql, Apache(4)
  12. Php And Mysql Applications(3)
  13. Getting Php 5 To Work With Mysql(0)
  14. Problem With A Mysql Join(2)
  15. The Artists Tutorials :mysql Basic Commands(0)
  1. Delete Problem With Id(4)
  2. [mysql]get Id Of Loged In User?(7)
  3. [mysql/php]need Som Basic Help(13)
  4. [php/mysql]id Trouble [resolved](3)
  5. Mysql Won't Update(4)
  6. Php + Mysql Question!(4)
  7. Tools Needed!(9)
  8. Best Sites For Learning Php-mysql(4)
  9. Php And Mysql Programming(2)
  10. Best Php And Mysql Editor For Noobs(6)
  11. Html Form!(4)
  12. Mysql Error(3)
  13. Create Table - Mysql Code - Help(1)


 



- Lo-Fi Version Time is now: 25th July 2008 - 09:02 PM