#1 (permalink)  
Old 08-14-2006, 04:38 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,438
Add One to an Integer within MySQL field?

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";
}
?>
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote

  #2 (permalink)  
Old 08-14-2006, 04:59 PM
Till's Avatar
Administrator
 
Join Date: Jan 2002
Location: Berlin, Germany
Posts: 1,453
Sure! At least in MySQL.


Code:
UPDATE table SET foo = foo +1 WHERE bar = x
Reply With Quote
  #3 (permalink)  
Old 08-14-2006, 06:54 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,438
Quote:
Originally Posted by Till
Sure! At least in MySQL.


Code:
UPDATE table SET foo = foo +1 WHERE bar = x
That's exactly what I was looking for. Thanks.
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Show Integer As Text in PHP? curtiss Programming and Scripting 1 05-27-2006 10:12 AM
Replacing a field separator during a read. NevadaSam Programming and Scripting 2 04-29-2006 02:53 PM
strip carriage returns & linefeed characters from form field amanxman Programming and Scripting 2 03-30-2006 07:52 AM
how to include id# field of db in url? gilgalbiblewhee Programming and Scripting 6 01-05-2006 06:15 PM
Clear my misunderstanding: 1 MySQL database for many programs? Kwak Databases 3 09-13-2005 10:55 AM


All times are GMT -5. The time now is 11:54 PM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter