Adding a value to a row using no variable

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sk8erh4x0r
Forum Commoner
Posts: 43
Joined: Wed May 26, 2004 8:27 pm

Adding a value to a row using no variable

Post by sk8erh4x0r »

I want to add 1 to a row that holds an integer without using something like this:

Code: Select all

$total = $row['hits'] + 1;

$query = "UPDATE `affiliates` SET `hits` = '$total' WHERE `id` = '$id'";
$result = mysql_query($query) or die(mysql_error());
Instead is there a way I could do it something like this?:

Code: Select all

$query = "UPDATE `affiliates` SET `hits` = '$total' WHERE `id` = 'id++'";
$result = mysql_query($query) or die(mysql_error());
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

UPDATE `table` SET `field` = `field` + 1 WHERE `id` = 5 LIMIT 1
Post Reply