Jump to content

Checking for idlers


karimali831

Recommended Posts

Hello!

 

Does anyone know an effective way to track inactive idlers in daily basis?

So that it will count the amount of days no data has been posted to the table. 

 

E.g.

 

User posts latest data and inserts timestamp 1282228120 which reads Thursday, August 19th 2010, 14:28:40 (GMT)

The days for inactivity should output as 8 days because no data has been posted from 20th August to today - 28th August.

 

Anyway I can achieve this?

Any information is appreciated, thanks.

Link to comment
Share on other sites

Hello karimali831,

I used to have the same problem a while ago, so I decided to create a function to fix the problem.

 

function returnTime($value) {
  $timeDiff 	= time()-$value;  // Get the difference in time
  $fullYears 	= floor($timeDiff/365.2422/24/60/60);  // Set the amount of years since $value
  $fullDays 	= floor($timeDiff/24/60/60)-($fullYears*365);  // Set the amount of dayss since $value
  $fullHours 	= floor($timeDiff/60/60)-($fullDays*24)-($fullYears*365*24);  // Set the amount of hours since $value
  $fullMinutes 	= floor($timeDiff/60)-($fullHours*60)-($fullDays*24*60)-($fullYears*365*24*60); // Set the amount of minutes since $value
  $fullSeconds 	= floor($timeDiff)-($fullMinutes*60)-($fullHours*60*60)-($fullDays*24*60*60)-($fullYears*365*24*60*60); // Set the seconds of years since $value

  // Now we check the difference and output correct timescale
  if($timeDiff >= '31536000') {
    return ''.$fullYears.' year(s)';
  } else if($timeDiff >= '86400' && $timeDiff < '31536000') {
    return ''.$fullDays.' day(s)';
  } else if ($timeDiff >= '3600' && $timeDiff < '86400') {
    return ''.$fullHours.' hour(s)';
  } else if ($timeDiff >= '60' && $timeDiff < '3600') {
    return ''.$fullMinutes.' minute(s)';
  } else if ($timeDiff < '60') {
    return ''.$fullSeconds.' second(s)';
  }
}

 

Simple call returnTime('Your Timestamp') wherever you want and it will show time since date in the correct format.

Hopefully this can help, if not let em know.

 

Thanks, Paul.

Link to comment
Share on other sites

Thanks! works fine with php max

 

$last_played = max($gc['new_date'],$gc['reply_date'],$gc['finalized_date']);

 

I also want to use it for php min excluding 0 values to find the longest idler:

 

   $getchallenges = safe_query("SELECT * FROM ".PREFIX."cup_challenges WHERE ladID='$ladID'");
      while($ds=mysql_fetch_array($getchallenges)) {
      
            
      if($ds['new_date']) 
         $new_date = $ds['new_date'];
      if($ds['reply_date']) 
         $reply_date = $ds['reply_date'];
      if($ds['finalized_date']) 
         $finalized_date = $ds['finalized_date'];
      
         $getmin = min($new_date,$reply_date,$finalized_date);   
       }
   
   return returnTime($getmin);

 

min() is not retrieving the values correctly.

I want to retrieve lowest value from columns new_date, reply_date and finalized_date excluding 0.

must I use array?

Link to comment
Share on other sites

Ohh right I see, could you give me some example data that will be passed from the folling fields from your database:

$ds['new_date']

$ds['reply_date']

$ds['finalized_date']

 

This may help me in understanding your situation a little more.

 

Thanks, Paul.

Link to comment
Share on other sites

Sure!

 

echo:

 

      echo '<br>newdate = '.$ds['new_date'].'';
      echo '<br>replydate = '.$ds['reply_date'].'';
      echo '<br>finalized date = '.$ds['finalized_date'].'';

 

Output:

 

newdate = 1282948140

replydate = 0

finalized date = 0

newdate = 1282955160

replydate = 0

finalized date = 0

newdate = 1282959480

replydate = 0

finalized date = 0

newdate = 1282960620

replydate = 0

finalized date = 0

newdate = 1282971660

replydate = 1282971720

finalized date = 01282971720

 

According to the output, I want it to return

returnTime('1282948140'); (lowest timestamp except 0)

 

Thanks again

Link to comment
Share on other sites

I think I have found a solution...

 

Replace the following

$getmin = min($new_date,$reply_date,$finalized_date);

 

With this

// Put value into an array
$getMin = array($new_date,$reply_date,$finalized_date);
//Filter out any NULL or FALSE values including '0'
//Then return the lowest value
$getMin = min(array_filter($getMin));

 

Hopefully this will help you karimali831.

 

Thanks, Paul.

Link to comment
Share on other sites

Thanks for your reply.

 

Now I get something, but I believe it picked out the incorrect value.

 

I echo $getMin but it gets:

1282971660 (highest in new_date column)

 

max is:

1282971720

 

$getMin needs to have min:

1282948140

 

   $getchallenges = safe_query("SELECT * FROM ".PREFIX."cup_challenges WHERE ladID='$ladID'");
      while($ds=mysql_fetch_array($getchallenges)) {
         
      if($ds['new_date']) 
         $new_date = $ds['new_date'];
      if($ds['reply_date']) 
         $reply_date = $ds['reply_date'];
      if($ds['finalized_date']) 
         $finalized_date = $ds['finalized_date'];
      
      $getMin = array($new_date,$reply_date,$finalized_date);
      $getMin = min(array_filter($getMin));
   
       }echo 'getmin = '.$getMin.'';
   
   return returnTime($getMin);

Link to comment
Share on other sites

My thought, I had to use your function inside the loop:

 

   $getchallenges = safe_query("SELECT * FROM ".PREFIX."cup_challenges WHERE ladID='$ladID'");
      while($ds=mysql_fetch_array($getchallenges)) {
         
      if($ds['new_date']) 
         $new_date = $ds['new_date'];
      if($ds['reply_date']) 
         $reply_date = $ds['reply_date'];
      if($ds['finalized_date']) 
         $finalized_date = $ds['finalized_date'];
      
      $getMin = array($new_date,$reply_date,$finalized_date);
      $getMin = min(array_filter($getMin));
   
   return returnTime($getMin);
  }

 

Thanks again very much for your help! :D

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.