Users Online Today in SSI

Started by Stop-TussiN, February 07, 2010, 03:32:56 AM

Previous topic - Next topic

Stop-TussiN

Hello, help to write a code fashion Users Online Today in SSI.php. That it was possible to output the given list on a site.

SMF 2.0RC2

Thanks in advance!

Stop-TussiN

Here I found this code on the forum, but it does not work  :(

// Who's been online today - very basic version 1.0
// the database table smf_members contains the last login unix time stamp for each member as well as the member name
function ssi_whosOnlineToday($output_method = 'echo'){
   $begining_today_time = strtotime(date('Y-n-j')); //get unix time at beginning of today
   $result = db_query("
      SELECT memberName
      FROM {$db_prefix}members
      WHERE lastLogin > $begining_today_time
      ORDER BY memberName ASC"); //find all members logged in since beginning of today
   $mc=mysql_num_rows($result); //total members logged in today
   while ($row = mysql_fetch_array($result)){ //print results, format as desired
      echo $row['memberName'];
      if($mc>1){echo ', ';}
      $mc--;
   }
}


Help me please

Stop-TussiN


Kays

Hi, that won't work as it's written for 1.1.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Stop-TussiN


Stop-TussiN


Kays

Hi, try this.


function ssi_whosOnlineToday($output_method = 'echo')
{
global $smcFunc;

$begining_today_time = strtotime(date('Y-n-j')); //get unix time at beginning of today

$request = $smcFunc['db_query']('', '
SELECT member_name
FROM {db_prefix}members
WHERE last_login > {int:begin_time}
ORDER BY member_name ASC',
array (
'begin_time' => $begining_today_time,
)
);

$mc = $smcFunc['db_num_rows']($request); //total members logged in today
while ($row = $smcFunc['db_fetch_assoc']($request))
{ //print results, format as desired
echo $row['member_name'];
if($mc>1){echo ', ';}
$mc--;
}
$smcFunc['db_free_result']($request);
}

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Stop-TussiN

Thank you very much! And how can I do to these names were not the text, and link to your profile? :)

Stop-TussiN

Solved the problem:)

function ssi_whosOnlineToday($output_method = 'echo')
{
   global $smcFunc;
   
   $begining_today_time = strtotime(date('Y-n-j')); //get unix time at beginning of today

   $request = $smcFunc['db_query']('', '
      SELECT member_name, id_member
      FROM {db_prefix}members
      WHERE last_login > {int:begin_time}
      ORDER BY member_name ASC',
      array (
         'begin_time' => $begining_today_time,
      )
   );

   $mc = $smcFunc['db_num_rows']($request); //total members logged in today
   while ($row = $smcFunc['db_fetch_assoc']($request))
   { //print results, format as desired
      echo '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '"' . $title . '>' . $row['member_name'] . '</a>';
      if($mc>1){echo ',&nbsp;';}
      $mc--;
   }
   $smcFunc['db_free_result']($request);
}


And how to make nicks were colored? that is an administrator-red, green moderator and so on.

Kays

For that we'll need to take a slightly different approach and load the memberContext array.


function ssi_whosOnlineToday($output_method = 'echo')
{
   global $smcFunc, $memberContext, $scripturl;
   
   $begining_today_time = strtotime(date('Y-n-j')); //get unix time at beginning of today

   $request = $smcFunc['db_query']('', '
      SELECT id_member
      FROM {db_prefix}members
      WHERE last_login > {int:begin_time}
      ORDER BY member_name ASC',
      array (
         'begin_time' => $begining_today_time,
      )
   );

   $mc = $smcFunc['db_num_rows']($request); //total members logged in today

   while ($row = $smcFunc['db_fetch_assoc']($request))
      $members[] = $row['id_member'];
   $smcFunc['db_free_result']($request);

loadMemberData($members);

foreach($members as $member)
{
loadMemberContext($member);

// Some basic color coding...
if (!empty($memberContext[$member]['group_color']))
echo '<a href="' . $scripturl . '?action=profile;u=' . $member . '" style="color: ' . $memberContext[$member]['group_color'] . ';">' . $memberContext[$member]['name'] . '</a>';
else
echo '<a href="' . $scripturl . '?action=profile;u=' . $member . '">' . $memberContext[$member]['name'] . '</a>';

if($mc>1){echo ',&nbsp;';}
$mc--;
}
}

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Stop-TussiN

Thank you very much!
Kays, I love you!  ;)

Kays


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

Advertisement: