Forum Gallery Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Go Back   SMCars - Car Blueprints > Discussion > Offtopic Discussion > Programming forums > Programming

Programming Programming Help Forum.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-20-2005
imported_envoy imported_envoy is offline
Administrator
 

Join Date: Jul 2002
Posts: 600
Points: -2,712
Send a message via MSN to imported_envoy
[CODE] Wasted time online for SMF Forum

OK, I just wrote this to show you guys a simple script for getting the top 10 users who have wasted the most amount of time on the board, hehe. It also calculates the total time logged in for everyone and does an average for the time logged in. If anyone can improve on this code, please do. I have a feeling that there is a simpler way of transforming the numbers of days/hours/minutes logged in to readable form. Anywho, here is the code, I tried to comment it as much as possible. I must also mention, this is for Simple Machines Forum 1.0.5. I am not sure if it works on 1.1b3. I would do the same thing for phpbb, but phpbb doesn't count the total time a user wastes on a forum.

Code:
<?
// Make sure this file goes into the same directory
// of your SMF forum.

// require the SMF Settings.php file
require("Settings.php");

// Connect to the database using the info from Setting.php
$connection=mysql_connect($db_server, $db_user, $db_passwd) OR DIE("Unable to connect to database");

// Select the database
@mysql_select_db("$db_name") or die( "Unable to select database");

// set the below variable to how many members you want to see
// example for the top 5 members would be
// $limit = 5;
$limit = 10;

// SQL/PHP Query to Get Total Time Online For Everyone
$sql = 'SELECT SUM(`totalTimeLoggedIn`) FROM `smf_members`';
$query = mysql_query($sql);
$array = mysql_fetch_array($query);
$total = $array[0];

// SQL/PHP to get total number of users registered
$sql = 'SELECT COUNT(*)
    FROM '.$db_prefix.'members';
$query = mysql_query($sql);
$array = mysql_fetch_array($query);
$members = $array[0];

// SQL Query to get top X members who have been on the most.
$sql = 'SELECT ID_MEMBER,memberName,totalTimeLoggedIn
    FROM '.$db_prefix.'members
    ORDER BY totalTimeLoggedIn DESC
    LIMIT 0,'. $limit;
$query = mysql_query($sql);
$total_count = mysql_numrows($query);

// lets end the php for now so we can create our table
?>
<table width="50%" cellspacing="0" cellpadding="0">
<tr>
<th width=\"25%\" align="left">Username</th>
<th width=\"25%\" align="left">Time Online</th>
</tr>
<?

// lets resume the php and do our for statement
for($n=0;$n<$total_count;$n++)
// for $n equals 0, and $n is less then $total_count, lets increase $n by 1.
{

// lets set our array from the query to $users_data
  $users_data = mysql_fetch_array($query);

// Time to calculate the time online in readable format
  $days = floor($users_data[totalTimeLoggedIn] / 86400);
  $hours = floor(($users_data[totalTimeLoggedIn] % 86400) / 3600);
  $minutes = floor(($users_data[totalTimeLoggedIn] % 3600) / 60);

// lets echo out the username in 1 column and time wasted online in the other column
  echo "<tr><td width=\"25%\">".$users_data[memberName]."</td>
  <td width=\"25%\">".$days."d".$hours."h".$minutes."m</td></tr>";
}

// make an average of the time online calculated for everyone
$avg = round($total/$members,2);

// now lets make that into readable form
$adays = floor($avg / 86400);
$ahrs = floor(($avg % 86400) / 3600);
$amins = floor(($avg % 3600) / 60);

// now lets echo out the columns for the average
echo "<tr><td width=\"25%\"><b>Average:</b></td><td width=\"25%\"><b>".$adays."d".$ahrs."h".$amins."m</b></td></tr>";

// and do the readable format for the total for everyone
$tdays = floor($total / 86400);
$thrs = floor(($total % 86400) / 3600);
$tmins = floor(($total % 3600) / 60);

// and then echo it out in columns and then end the table.
echo "<tr><td width=\"25%\"><b>Total:</b></td><td width=\"25%\"><b>".$tdays."d".$thrs."h".$tmins."m</b></td></tr>";
echo "<tr><td width=\"25%\"><b>Members:</b></td><td width=\"25%\"><b>".$members."</b></td></tr></table>";

?>
Here is the result:
Click Here
Reply With Quote
  #2 (permalink)  
Old 07-21-2005
GaS's Avatar
GaS GaS is offline
V6 Inside Decal
 

Join Date: Feb 2005
Posts: 350
Points: -2,265
Re: [CODE] Wasted time online for SMF Forum

:O
Im the fourth one
This means im one of the guys that sit on one page clicking the refresh buton and not knowing what to do

.....**** happenz.....
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:06 PM.



Design By: Miner Skinz.com
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC6
vBCredits v1.4 Copyright ©2007, PixelFX Studios