Update all records with this "field"[Topic Solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Update all records with this "field"[Topic Solved]

Post by SirChick »

Is there a way to make a script that does this:

Find all records with $Currentstat less than $Max...

Then with all records found with that... add X amount on to "Current field" ?

But this script needs to run on its own as i will be using it as a Cron so even if no one is logged in it should still work.
And if $CurrentStat is equal to Max then do nothing?
Last edited by SirChick on Sun Oct 14, 2007 5:18 pm, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Code: Select all

$sql = "UPDATE mytable SET Current_field=Current_field+$X WHERE Currentstat<$Max";
(#10850)
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post by SirChick »

Thank but there is one problem.

$Max is in the database.... how would it check every user's $Max (as they are all different per user) ?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Replace $Max with the fieldname that contains $Max.
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Post by SirChick »

thankyou
Post Reply