almightyegg Posted October 26, 2006 Share Posted October 26, 2006 how would i go about coding a reset (at midnight) when all my members get a daily stock of something...??like they start with 100 points in something and they use them up during the day...then at midnight it goes back to 100 OR it they start with 100 and use X and then at midnight they will have X+100...get me?? Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/ Share on other sites More sharing options...
Orio Posted October 26, 2006 Share Posted October 26, 2006 Cron job and an update query :)Orio. Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114787 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 ??? how would i do that???? im still a php baby :( Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114789 Share on other sites More sharing options...
HuggieBear Posted October 26, 2006 Share Posted October 26, 2006 Do they always get 100 added every night? If I register and don't log in for two weeks, when I log in next time, will I have 1400 points?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114814 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 yes...but i would like to also add a limit that it only go up to a certain amount... Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114821 Share on other sites More sharing options...
HuggieBear Posted October 26, 2006 Share Posted October 26, 2006 In that case, why not use timestamps. I'm not going to provide you with the code, just an idea.1. A new user logs into your site the first day they register, you credit them with 100 points and store in the database the time of login.2. The next time they login, you take the current timestamp and subtract the one stored in the datbase and round it down to the nearest day to work out the number of elapsed days.3. You credit them with that number of elapsed day times 100 (up to the limit you've set) and then log the new timestamp for next time they log in.Now for someone who's worked a lot with timestamps, dates, time functions etc. This shouldn't bee too difficult, unfortunately that person isn't me. :(RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114834 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 do you know anybody that would know how to do this?? Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114852 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 can anybody help me code this??[tt]1. A new user logs into your site the first day they register, you credit them with 100 points and store in the database the time of login.2. The next time they login, you take the current timestamp and subtract the one stored in the datbase and round it down to the nearest day to work out the number of elapsed days.3. You credit them with that number of elapsed day times 100 (up to the limit you've set) and then log the new timestamp for next time they log in.[/tt] Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114887 Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 we are not here to write your code for you. We are here to help debug your code that you yourself are working on. If you want someone to write your code for you, please go post in the freelance forum (read the forum rules before doing so). Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114889 Share on other sites More sharing options...
Orio Posted October 26, 2006 Share Posted October 26, 2006 I have no problems writing code for people :)For number 1,you just need to add two columns- one for the points and one for timestamps. And in the query that creates their account, insert 100 to the points column and the returned value from [url=http://www.php.net/manual/en/function.time.php]time()[/url] to the "last_login" column (the one I said that hold timestamps).2 and 3[code]<?php//Validate username and pass, start sessions etc etc'$query = "SELECT ('last_login','points') FROM `Users_Table` WHERE username_column='$username'";$result = mysql_query($query);$row = mysql_fetch_array($result); //since there's only one user with the called $username no need to run a loopif(time()-$row['last_login'] > 60*60*24){ $days = floor( (time()-$row['last_login']) / (60*60*24) ); $points = $row['points'] + $days*100; $timestamp = $row['last_login'] + $days*60*60*24; mysql_query("UPDATE `Users_Table` SET points='$points',last_login='$timestamp' WHERE username_column='$username'");}?>[/code]Orio :) Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114910 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lordofth/public_html/welcome.php on line 98[code=php:0]<?$query = "SELECT ('last_login','mot') FROM users WHERE username='$username'";$result = mysql_query($query);$row = mysql_fetch_array($result);if(time()-$row['last_login'] > 60*60*24){ $days = floor( (time()-$row['last_login']) / (60*60*24) ); $mot = $row['points'] + $days*100; $timestamp = $row['last_login'] + $days*60*60*24; mysql_query("UPDATE users SET mot='$mot',last_login='$timestamp' WHERE username='$username'");}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114950 Share on other sites More sharing options...
Orio Posted October 26, 2006 Share Posted October 26, 2006 Try changing the three first lines to:$query = "SELECT last_login,mot FROM users WHERE username='$username'";$result = mysql_query($query) or die(mysql_error());$row = mysql_fetch_array($result);Orio. Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114954 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 no errors...but there is no way of telling whether it works yet, unless i go change last login time in database? would that work?? Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114957 Share on other sites More sharing options...
Orio Posted October 26, 2006 Share Posted October 26, 2006 Yeah. Reduce 3601 from it and see if you get 100 points and the timestamp is being updated. Then run diffrent tests to check :)Orio. Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114959 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 it isnt posting the new last_login time into it........plus ive now changed it to a datetime field because it works the same but i also know how to make that gmt time :P[code=php:0]<?$query = "SELECT last_login,mot FROM users WHERE username='$username'";$result = mysql_query($query) or die(mysql_error());$row = mysql_fetch_array($result);if($time-$row['last_login'] > 60*60*24){ $days = floor( ($time-$row['last_login']) / (60*60*24) ); $mot = $row['points'] + $days*100; $timestamp = $row['last_login'] + $days*60*60*24; mysql_query("UPDATE users SET mot='$mot',last_login='$time' WHERE username='$username'");//its here that there is a problem as it isnt putting in the information}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114973 Share on other sites More sharing options...
Orio Posted October 26, 2006 Share Posted October 26, 2006 That's not my error but yours =PI posted in my original post last_login='$timestamp', and you changed it to $time from some reason :)Orio. Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114979 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 it didnt post with $timestamp either :P $time = date(info is in here) its an error in the code so its not posting... Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114983 Share on other sites More sharing options...
Orio Posted October 26, 2006 Share Posted October 26, 2006 Why did you change time() to $time?Here's how the code should be:[code]<?php$query = "SELECT last_login,mot FROM users WHERE username='$username'";$result = mysql_query($query) or die(mysql_error());$row = mysql_fetch_array($result);$now=time();if($now-$row['last_login'] > 60*60*24){ $days = floor( ($now-$row['last_login']) / (60*60*24) ); $points = $row['points'] + $days*100; $timestamp = $row['last_login'] + $days*60*60*24; mysql_query("UPDATE users SET mot='$mot',last_login='$timestamp' WHERE username='$username'");}?>[/code]$timestamp is define this way- [b]$timestamp = $row['last_login'] + $days*60*60*24[/b] and not as the current timestamp. This is inorder not to loose part of days- If it was updated in this way, only if you haven't logged in for 24 hours you get the points.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114987 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 im on an american server, therefore timestamp is at there time...i dont know how to change timestamp to gmt but i can change time() Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114992 Share on other sites More sharing options...
Orio Posted October 26, 2006 Share Posted October 26, 2006 Whatever. I know what I did should work.Any problems with the script?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-114995 Share on other sites More sharing options...
almightyegg Posted October 26, 2006 Author Share Posted October 26, 2006 i ut all your code in and set the database a day behind and it didnt do anything....[code=php:0]<?$query = "SELECT last_login,mot FROM users WHERE username='$username'";$result = mysql_query($query) or die(mysql_error());$row = mysql_fetch_array($result);$now=time();if($now-$row['last_login'] > 60*60*24){ $days = floor( ($now-$row['last_login']) / (60*60*24) ); $points = $row['points'] + $days*100; $timestamp = $row['last_login'] + $days*60*60*24; mysql_query("UPDATE users SET mot='$mot',last_login='$timestamp' WHERE username='$username'");}?>[/code]there must be a reason why it isnt posting the new timestamp in......should $timestamp not be $now?? Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-115006 Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 ...and that's why we don't write code for people here. That's why it's better left to freelancers who have access to the servers to make it work, for people who don't want to learn it on their own. Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-115036 Share on other sites More sharing options...
HuggieBear Posted October 26, 2006 Share Posted October 26, 2006 Oh dear, what have I started. I'm glad to see the method's been passed as acceptable... lolHuggie Quote Link to comment https://forums.phpfreaks.com/topic/25184-reset-automatically/#findComment-115125 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.