View Full Version : Big help?
[Nicolas]
03-02-2011, 11:19 PM
This is for a very big script, please help!
I would like to have something like this: the user logs in, he/she earns points by the hour. How can PHP tell how many points a user will have? The user starts out with 1000 points, and can spend it one random things. Within one hour, he/she earns 50 pts., it should do this each hour. Even when the user is logged off. Please help! I know very little about PHP. Please point the right direction :) Thank you!
P.S.
I will ask many different questions in this topic. :P
djr33
03-02-2011, 11:27 PM
On the initial login (or registration) store the current timestamp. Then to calculate the number of points, do this math: ($original-$current)/(60*60). That will be the original time (the stored timestamp) minus the current timestamp divided by minutes per hour and seconds per minute... in other words, that will give you the number of hours the account has existed. Multiply that by 50 points or whatever you'd like.
Alternatively you could use a cron job to give 50 points to every registered user every hour.
[Nicolas]
03-02-2011, 11:28 PM
Huh? Lol, sorry, but I didn't understand half of that...
djr33
03-02-2011, 11:30 PM
Read it a few more times, and read it slowly. It will eventually make sense. That's an answer to your question. If you need someone to do this for you, then you'll need to make it a paid request. Slow down, and take your time, and you'll be able to do it by yourself.
[Nicolas]
03-02-2011, 11:34 PM
Ok, I sorta get it. But how can I save a PHP Variable for the time? (timestamp)
Just taking a guess on how that would be done...
djr33
03-02-2011, 11:35 PM
Save it to the user account. If you have user accounts you must have some way of storing this already. For example, a database.
[Nicolas]
03-02-2011, 11:41 PM
Hmm... Wow! This is confusing, I understand your last post, but all the other stuff is another story. OK, let's start from the beginning. Can you provide me with some information on how to make a register page that creates a user's page? Thanks !
djr33
03-02-2011, 11:47 PM
All I have answered is about storing the points. Creating a user system is both more complicated and more common, so you can easily find lots of different tutorials about how this would be done. You could even borrow an existing system such as from a free bulletin board and try to modify and extend it for your needs.
You will need to start with the basics of using PHP and MySQL. (Another kind of database would also work, but MySQL is the most common. For this type of system, a database is the best option, though it is technically possible to do it using flat files alone.)
This is a good tutorial to get started:
http://php-mysql-tutorial.com
Please note that you're not asking easy questions, so the answers aren't easy either. But you can accomplish what you want with enough time. It just won't be fast.
[Nicolas]
03-03-2011, 12:29 AM
Thank you! :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.