Is there any SQL query that will automatically add 1 to an integer within an SQL field? Obviously I know how to use PHP to do it, but I'm just checking to see if there's any mySQL query that can do it automatically for me.
In other words, my PHP would look something like this:
PHP Code:
<?php
$sql_query = mysql_query("SELECT `number` FROM `numbers` WHERE `pageid` = '$pageid'", $link);
while($rs = mysql_fetch_array($sql_query)) {
$num = $rs[0] + 1;
}
$sql_query = "UPDATE `numbers` SET `number` = '$num' WHERE `pageid` = '$pageid'";
if(mysql_query($sql_query)) {
echo "Record updated successfully";
}
?>
I'm just trying to make sure that there isn't some way I could do something like:
PHP Code:
<?php
$sql_query = "UPDATE `numbers` SET `number` = +1 WHERE `pageid` = '$pageid'";
if(mysql_query($sql_query)) {
echo "Record updated successfully";
}
?>