Need help with If/ELSE
Posted: Sat Nov 15, 2008 11:24 am
Hi,
I'm trying to make a cron file that runs each night, and I want it to work one way for one type of user, and runs another for another type of user.
What I'm trying to do is have it check the user status, if they are a donating user then it updates their account at a faster rate. If they are not a donating user, it updates at the standard rate.
Here is what I have now, I think I have my while in the wrong place?
What it does now is it updates all uses and resets their stats to the max limit. Which is not what I want it to do, it should only increase it by the set amounts below.
If I use just a fetchrow then it update all users at the donating rate. I think because it's only looking at the first row from the query. So this is why I think the while is in the wrong place????
Does this look close to being right?
I'm trying to make a cron file that runs each night, and I want it to work one way for one type of user, and runs another for another type of user.
What I'm trying to do is have it check the user status, if they are a donating user then it updates their account at a faster rate. If they are not a donating user, it updates at the standard rate.
Here is what I have now, I think I have my while in the wrong place?
What it does now is it updates all uses and resets their stats to the max limit. Which is not what I want it to do, it should only increase it by the set amounts below.
If I use just a fetchrow then it update all users at the donating rate. I think because it's only looking at the first row from the query. So this is why I think the while is in the wrong place????
Does this look close to being right?
Code: Select all
$currenttime = time();
$checkstatus = $db->execute("Select `Mafia_Platty` FROM `players`");
while ($checkstatus1 = $checkstatus->fetchrow()) {
if ($checkstatus1['Mafia_Platty'] > $currenttime) //currently a donator
{
$query = $db->execute("update `players` set hp = IF((hp + 10)>maxhp, maxhp, (hp + 10))" );
$query = $db->execute("update `players` set energy = IF((energy + 15)>maxenergy, maxenergy, (energy + 15))" );
$query = $db->execute("update `players` set fat = IF((fat - 5)< 0, 0, (fat - 5))" );
$query = $db->execute("update `players` set Awake = IF((Awake + 2)>Max_Awake, Max_Awake, (Awake + 2))" );
$query = $db->execute("update `players` set Intent = IF((Intent + 3)>Max_Intent, Max_Intent, (Intent + 3))" );
}
else //Not a donator
{
$query = $db->execute("update `players` set hp = IF((hp + 5)>maxhp, maxhp, (hp + 5))" );
$query = $db->execute("update `players` set energy = IF((energy + 10)>maxenergy, maxenergy, (energy + 10))" );
$query = $db->execute("update `players` set fat = IF((fat - 5)< 0, 0, (fat - 5))" );
$query = $db->execute("update `players` set Awake = IF((Awake + 2)>Max_Awake, Max_Awake, (Awake + 2))" );
$query = $db->execute("update `players` set Intent = IF((Intent + 2)>Max_Intent, Max_Intent, (Intent + 2))" );
}
}