4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Increasing Turns
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sat Jan 25, 2003 2:22 pm (21 years, 2 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sat Jan 25, 2003 2:23 pm (21 years, 2 months ago) Reply with QuoteBack to Top

So what's the question? Very Happy

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sat Jan 25, 2003 2:26 pm (21 years, 2 months ago) Reply with QuoteBack to Top

Daniel wrote:
So what's the question? Very Happy


oops. Laughing Spent all that time typing and forgot to ask the question. I'm having a bad day Wink

The question is... Does anyone know how I can do this?

Thanks,

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sat Jan 25, 2003 2:27 pm (21 years, 2 months ago) Reply with QuoteBack to Top

What exactly do you need help with? The cron? Adding the turns?

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sat Jan 25, 2003 2:29 pm (21 years, 2 months ago) Reply with QuoteBack to Top

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 Smile

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sat Jan 25, 2003 2:32 pm (21 years, 2 months ago) Reply with QuoteBack to Top

Try this: Question
Code:
$sql = "UPDATE warrior_turns
SET turns = turns +
WHERE turns != 2000";

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sat Jan 25, 2003 2:34 pm (21 years, 2 months ago) Reply with QuoteBack to Top

Daniel wrote:
Try this: Question
Code:
$sql = "UPDATE warrior_turns
SET turns = turns +
WHERE turns != 2000";


Thanks Smile Looks hopeful, I will give it a go and report back.

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sat Jan 25, 2003 2:44 pm (21 years, 2 months ago) Reply with QuoteBack to Top

Daniel wrote:
$sql = "UPDATE warrior_turns
SET turns = turns +1
WHERE turns != 2000";


Yup! It works Smile thanks a lot (I just had to make a minor alteration which is in bold above)

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Sun Jan 26, 2003 4:22 pm (21 years, 2 months ago) Reply with QuoteBack to Top

Daniel wrote:
Try this: Question
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...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Jan 26, 2003 4:25 pm (21 years, 2 months ago) Reply with QuoteBack to Top

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.

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Sun Jan 26, 2003 4:28 pm (21 years, 2 months ago) Reply with QuoteBack to Top

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...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.312356 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme