|
|
|
|
![]() ![]() |
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. |
|
|
|
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! |
|
|
|
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...
|
|
|
|
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... |
|
|
|
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!! |
|
|
|
Jul 18 2005, 05:51 AM
Post
#6
|
|
|
Desperately seeking "any key" to continue... ![]() Group: Admin Posts: 3,434 Joined: 23-April 05 From: Trap17 storage box Member No.: 6,042 |
Question answered: topic closed.
|
|
|
|
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 |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 25th July 2008 - 09:02 PM |