Author |
Message |
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sat Jan 25, 2003 2:22 pm (21 years, 11 months ago) |
|
Hi,
I am currently writing an online game in PHP every 3 minutes I am going to run a cron that increases every user's turns by one unless they have 2000 turns already.
My database has the fields:
uid (a integer that is the unique user number. This starts from 1 and goes up although some numbers may be missing if a user has been deleted)
turns (The number of thurens the user has. Each user may have different numbers of turns)
My database table currently looks like this:
uid turns
1 1500
2 500
3 275
5 167
6 1335
The table is caled warrior_turns
Thanks, |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sat Jan 25, 2003 2:23 pm (21 years, 11 months ago) |
|
So what's the question? |
________________________________
|
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sat Jan 25, 2003 2:26 pm (21 years, 11 months ago) |
|
Daniel wrote: | So what's the question? |
oops. Spent all that time typing and forgot to ask the question. I'm having a bad day
The question is... Does anyone know how I can do this?
Thanks, |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sat Jan 25, 2003 2:27 pm (21 years, 11 months ago) |
|
What exactly do you need help with? The cron? Adding the turns? |
________________________________
|
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sat Jan 25, 2003 2:29 pm (21 years, 11 months ago) |
|
Daniel wrote: | What exactly do you need help with? The cron? Adding the turns? |
The SQL/PHP code to add the turns if the user doesn't allready have 2000.
My Host will set up the cron for me |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sat Jan 25, 2003 2:32 pm (21 years, 11 months ago) |
|
Try this: Code: | $sql = "UPDATE warrior_turns
SET turns = turns +
WHERE turns != 2000"; |
|
________________________________
|
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sat Jan 25, 2003 2:34 pm (21 years, 11 months ago) |
|
Daniel wrote: | Try this: Code: | $sql = "UPDATE warrior_turns
SET turns = turns +
WHERE turns != 2000"; |
|
Thanks Looks hopeful, I will give it a go and report back. |
________________________________ Iyonix |
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sat Jan 25, 2003 2:44 pm (21 years, 11 months ago) |
|
Daniel wrote: | $sql = "UPDATE warrior_turns
SET turns = turns +1
WHERE turns != 2000"; |
Yup! It works thanks a lot (I just had to make a minor alteration which is in bold above) |
________________________________ Iyonix |
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Sun Jan 26, 2003 4:22 pm (21 years, 11 months ago) |
|
Daniel wrote: | Try this: Code: | $sql = "UPDATE warrior_turns
SET turns = turns +
WHERE turns != 2000"; |
|
I personally would use this:
Code: | $sql = "UPDATE warrior_turns
SET turns = turns +1
WHERE turns < 2000"; |
|
________________________________ It's turtles all the way down... |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sun Jan 26, 2003 4:25 pm (21 years, 11 months ago) |
|
It really depends if there's a chance that a record might accidentally get more than 2000 turns. In that case they could have, for example, 2005 turns and you wouldn't want to give them anymore. |
________________________________
|
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Sun Jan 26, 2003 4:28 pm (21 years, 11 months ago) |
|
even if you think there isn't a chance, something you didn't think of could happen so it's a good idea to just play it safe |
________________________________ It's turtles all the way down... |
|
|
|
|