Jump to content


Photo

reset automatically


  • Please log in to reply
22 replies to this topic

#1 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 03:01 PM

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??
Visit my Game - Under Construction

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 03:03 PM

Cron job and an update query :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 03:05 PM

??? how would i do that???? im still a php baby :(
Visit my Game - Under Construction

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 26 October 2006 - 03:30 PM

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?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 03:36 PM

yes...but i would like to also add a limit that it only go up to a certain amount...
Visit my Game - Under Construction

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 26 October 2006 - 03:52 PM

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.  :(

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 04:18 PM

do you know anybody that would know how to do this??
Visit my Game - Under Construction

#8 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 05:03 PM

can anybody help me code this??

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.

Visit my Game - Under Construction

#9 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 October 2006 - 05:07 PM

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).


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#10 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 05:23 PM

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 time() to the "last_login" column (the one I said that hold timestamps).

2 and 3
<?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 loop
if(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'");
}

?>


Orio :)
Think you're smarty?

(Gone until 20 to November)

#11 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 05:59 PM

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lordofth/public_html/welcome.php on line 98
<?
$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'");
}
?>

Visit my Game - Under Construction

#12 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 06:02 PM

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.
Think you're smarty?

(Gone until 20 to November)

#13 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 06:05 PM

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??
Visit my Game - Under Construction

#14 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 06:08 PM

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.
Think you're smarty?

(Gone until 20 to November)

#15 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 06:26 PM

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

<?
$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
}
?>

Visit my Game - Under Construction

#16 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 06:34 PM

That's not my error but yours =P
I posted in my original post last_login='$timestamp', and you changed it to $time from some reason :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#17 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 06:37 PM

it didnt post with $timestamp either :P $time = date(info is in here) its an error in the code so its not posting...
Visit my Game - Under Construction

#18 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 06:47 PM

Why did you change time() to $time?

Here's how the code should be:
<?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'");
}

?>

$timestamp is define this way- $timestamp = $row['last_login'] + $days*60*60*24 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.
Think you're smarty?

(Gone until 20 to November)

#19 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 26 October 2006 - 06:49 PM

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()
Visit my Game - Under Construction

#20 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 06:53 PM

Whatever. I know what I did should work.
Any problems with the script?

Orio.
Think you're smarty?

(Gone until 20 to November)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users