TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-01-2008, 02:14 PM   #1 (permalink)
The Wanderer
 
Join Date: Mar 2008
Location: United Kingdom
Posts: 22
Thanks: 1
boycoda is on a distinguished road
Default +1 in mysql ?

Hello everyone,

Say for example I have a field in a mysql row, with the value of 4. Now I want to be able to update that value to 5 in php.

What would be the best way to do that?

Remember though, that it has to +1 on to the current mysql row field value. UPDATING a field is easy, but i've not done a +1 of value before.

So say,

$age = $row['age'];



$agesplus = $newage;

$newage would be 5, but how would it do that?
Send a message via MSN to boycoda Send a message via Skype™ to boycoda
boycoda is offline  
Reply With Quote
Old 09-01-2008, 02:23 PM   #2 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

PHP Code:
$szQuery sprintf("UPDATE table SET age = (age + 1) WHERE id = %d"$iId); 
maZtah is offline  
Reply With Quote
Old 09-01-2008, 04:04 PM   #3 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Here's what maZtah said but just with the plain old SQL:
Code:
UPDATE my_table SET age = (age + 1) WHERE username = 'MyUserName'
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-02-2008, 08:35 AM   #4 (permalink)
The Wanderer
 
Join Date: Mar 2008
Location: United Kingdom
Posts: 22
Thanks: 1
boycoda is on a distinguished road
Default

Ah that's great, thanks.
Send a message via MSN to boycoda Send a message via Skype™ to boycoda
boycoda is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:14 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design