kirbyweb Posted November 16, 2009 Author Share Posted November 16, 2009 nvm I get it. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 16, 2009 Share Posted November 16, 2009 Move your database code into the if structure, right now the only thing the if structure is doing is deciding what to print. Include the database code with that also. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 16, 2009 Author Share Posted November 16, 2009 Thanks. Link to comment Share on other sites More sharing options...
thescientist Posted November 17, 2009 Share Posted November 17, 2009 basically only add money to the bank IF it is less than 500, else exit, or stop, or return, or whatever you want to have your code do based on it meeting/not meeting certain conditions. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 Ok now when I upgrade the bank the money gets lowered, so when it gets lowered then the update happens with the minutes it missed, how do I stop that? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 If you do not know what I mean let me know. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 I'm not sure what you mean. You tend to describe your problems in abstract terms, which I know makes sense to you but it's not how I think. Like you say when you upgrade the bank the money gets lowered, but I'm not sure what that means in terms of the actual data. In terms of the numbers in the database, I'm not sure what it means to upgrade a bank, or to lower the money. The way I think of web applications is that you've got your data stored in the database, and virtually every page is either reading information from the database, or writing information to it. So, I tend to think in terms of data either going in or going out, when you use the abstract terms like banks and money it's hard for me to follow what that means for your application. In fact, it might help you to think of the pages as input/output for the database instead of anything more. I understand where you're coming from, because I was there at one point, I'm just having a hard time following because I don't know the details of your application. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 ok instead of money lets say numbers, the number goes up every minute at 500 it stops, if 15 minutes have gone by it will still be at 500 but when I make the number to 0 then it will go up 15 numbers. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 I'm not sure if this applies, but you may need to use a cron job. A cron job is like a scheduled task in Windows, you can schedule a cron job to run in the future. I've got an application that uses a cron job to send emails, for example. So this job runs every minute, and it's a PHP script that checks for emails in the database ready to send and sends emails if there are any to send. If your application requires things to happen each minute, then you might want to create a PHP script that you can schedule to run each minute which will check for things in your database that need to be updated. So you could have a script that runs through everyones accounts and updates their money or whatever your application does. Does that sound like what you need to do? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 I do not want to use cron jobs is there any other way? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 I'm still not real clear on what you're trying to do, I don't understand what you mean by this: if 15 minutes have gone by it will still be at 500 but when I make the number to 0 then it will go up 15 numbers.Do you want something to run every minute, or do you want it to keep track of the last time you loaded the page and just calculate what needs to happen for the number of minutes that passed? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 OK the number goes up every minute, when it reaches at 500 then it stops going up every minute, if 15 minutes have past and the number is still at 500 it will not go up, so 15 minutes past, lets say I change the number back to 0 from my db, then since 15 minutes past, (it was at 500 so it would not go up anymore) the number would then go from 0 to 15, since 15 minutes past when it was at 500. How do I stop this. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 Isn't that what you want to happen? If the max is 500 and it increases by 1 every minute as long as it is under the max, and if you reset it to 0 it will start going up again. Isn't that how you would want it to work? Or are you saying that if it idles for 15 minutes and then you reset it, that it immediately jumps to 15? Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 The last part, if it stops at 500 and it stays like that for 15 minutes and I reset it to 0 it jumps to 15. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 It sounds like you're only updating the timestamp when you update the money. You need to update the timestamp every time you check, even if the money wasn't updated. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 ????? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 I know this isn't the code you're using now, but look at it: if ($username['money']>=500&&$username['bank']<1){die('User\s money 500');}if ($money > 0) { //lets update users table mysql_query("UPDATE `castle wars users` SET lastupdate=lastupdate+$extraTime, money=money+$money WHERE id= '$username[id]'") or die(mysql_error());} It updates the timestamp and the money. There is nothing else where it updates the timestamp. It only updates the timestamp if it also updates the money. You need to update the timestamp always, regardless of whether or not the money is updated also. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 I have the die as echo, then I have else the code.Now all I need to know is how to make it so that when I reset it to 0 it will not go up the 15 minutes. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 I just told you. Read what I wrote until you understand it. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 OK and to do this I do? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 You. Update. The. Timestamp. On. Every. Request. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 I will try and figure out how if you will not help. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 This is part of my code, is this correct?Now it does not update the money regardless if its 500 or not. $username = mysql_fetch_array($query);$last = $username['lastupdate']; //timestamp from db$extraTime = time() - $last;$money = floor($extraTime / 60);if ($username['money']<499){if ($money > 0) { //lets update users table mysql_query("UPDATE `castle wars users` SET lastupdate=lastupdate+$extraTime, money=money+$money WHERE id= '$username[id]'") or die(mysql_error());}echo 'user\'s money:'. ((int)$username['money']+(int)$money) .'money.';}else echo 'user\'s money: 500'; //lets update users table mysql_query("UPDATE `castle wars users` SET lastupdate=lastupdate+$extraTime WHERE id= '$username[id]'") or die(mysql_error());?> Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 I will try and figure out how if you will not help.If I won't help? What do you think I'm doing here? The point is to get you to try things and figure out how this works. This is your project, not mine. If you don't want my help, just say so.I don't see any errors in that code, that will update the money if the user has 498 or less and the money to add is greater than 0. If the user has more than 498 then it will write that the user has 500. But if it updates the money then it will update the timestamp twice, once when it updates the money and once at the end. It should only update the timestamp at the end. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 But what about if it is less then 498 will it update the timestamp? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.