Cron jobs and if statements.

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
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Cron jobs and if statements.

Post by Mightywayne »

Hello there.

I'm actually having a problem with the logic behind this, I just can't seem to understand how I'm going to make it happen. What I need is...

I run a script every 24 hours that changes a user, right? Let's say every 24 hours I give them 1+ reputation for staying. Okay, but now let's say that user is special, like they are a helper or something, so every 24 hours, they'll get +2 rep instead.

What I don't get is the actual if statement for that...

Like, if ($userstatus == 'helper'), then it would only upgrade those that were considered helpers with +2, and then I guess it'd be like "else, just give +1 rep".

My script looks like this.

Code: Select all

mysql_query("UPDATE user SET inactivedays = inactivedays+1");
Quite basic indeed. So basically my question, summed up, is how would I target EVERYONE that had a certain attribute, and do it to that single group only? Sorry if I sound confusing, I'm trying my best. xD
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

... WHERE `status` = 'helper'
?
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

No lolz I know how to do that.

It's supposed to run on an if statement, you know? So it auto-runs cuz it's a cron job, right, but I don't know how to run the if statement in the first place for a whole group, because I don't know how to get the stat of being a helper for EVERYBODY.

Normally, I'd just be like

Code: Select all

$status = mysql_query("SELECT status FROM user WHERE username = '$user'");
(fetch)
(target fetched statement)

if ($status == 'helper')
(give two rep)
else
(give one)
But see, I can't do the username = '$user' thing, because the cron updates EVERYONE. So if I select all from the database, it won't work correctly because of having too many targets.
Post Reply