View Single Post
Old 11-15-2012, 02:14 PM   PM User | #1
Custard7A
Regular Coder

 
Custard7A's Avatar
 
Join Date: Jul 2010
Location: Australia
Posts: 269
Thanks: 32
Thanked 32 Times in 32 Posts
Custard7A is an unknown quantity at this point
Native Integer Incrementing (Existing Value)

Hi guys, I have a rather simple issue. I have a SMALLINT column, and I want this value to rise by one each-time I use that row (Basically this is recording the number of views on that row).
At the moment I am doing this (Stripped-down for the example):

PHP Code:

 
// After selecting the row I want, with an associative array.

 
$new_value = ++$result['views']; // Increment with php, and call an UPDATE..

 
$mysqli->query("UPDATE table_name SET views = $new_value WHERE row_id = $variable"); 
This seems like something might exists that can do this within MySQL. So, my questions would be..

1. Is there a way to increment an existing column without specifically calling UPDATE on it?

.. else..

2. Is there a way to increment it with SQL, so I can just do this in the query?
Custard7A is offline   Reply With Quote