Page 1 of 1

Adding a value to a row using no variable

Posted: Wed Sep 14, 2005 6:03 pm
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());

Posted: Wed Sep 14, 2005 6:06 pm
by josh
UPDATE `table` SET `field` = `field` + 1 WHERE `id` = 5 LIMIT 1