Jump to content

time interval help


Rihoj

Recommended Posts

Hello, I consider myself somewhat new to php. I understand most of it, but I usually just have to play around with it, instead of code it straight like i can html and css. So here is my problem. I want to have a site that will update a value according to what time it is, so like everyday at noon a number is increased. My site is set up so that when a user logs in they see how much money they have, and I want that every 24 hours that number is increased for each person by a certain amount. I am not sure how I should go about doing this though? Cause I want to to change for all the users weather they are logged in or not.

Link to comment
Share on other sites

I thought I had it figured out, but I can not manage to get it to work right. Here is what I have so far

 

$avvy = "SELECT * FROM phpbb_dseusers WHERE user_id =" . $user->data['user_id'];
$result = mysql_query($avvy) or die (mysql_error());

while($row = mysql_fetch_array($result))
{
$link = $row['user_avatar'];
$width = $row['user_avatar_width'];
$height = $row['user_avatar_height'];
$ship = $row['user_ship'];
$money = $row['user_money'];

$time = $user->data['user_lastvisit'];
$system = gettimeofday();
$interval = (60);
}


if($time+$interval == $system[sec])
{$time = $system;
$money = $money+10;
$user->data['user_money'] = $money;
}

 

the other variables are for other things

Link to comment
Share on other sites

You could always have a field in a database, that basically lets YOU know if the user has collected their gained money within the pass 24 hours. Then use time() and check the difference between the time last collected.

 

So we can do something like this:

 

<?php
$sql = "SELECT * FROM `phpbb_dseusers` WHERE `user_id` = " . $user->date['user_id'];
$res = mysql_query($sql) or die(mysql_error());

while($row = mysql_fetch_assoc($res)){
# do other things we'll do time
$time = time();
$last = $row['last_collected']; # you might have to add this into your database
$day = 3600*24;
$total = $time-$last;
$collection = $row['collected'];

if($collection == '0'){
# give points for first time
# update last_collected field with time();
# update collected with the number 1
}else {

	if($total >= $day){
	# give points
	# update last_collected field with time();
	}
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.