TinyPortal

Development => Block Codes => Topic started by: whitesox on May 14, 2009, 10:45:27 AM

Title: [Block] Most recent visitors to site
Post by: whitesox on May 14, 2009, 10:45:27 AM
i want a code 4 a block like this:

member  last online
------------------

member1    03:30
member2    03:12
member3    02:45

can any give me this code ??

i hope u unsterstand me ... my english is not so good  :tickedoff:

Title: Re: Block "Last Members WAS online"
Post by: JPDeni on May 14, 2009, 02:54:56 PM
How many? Do you want to include the ones who are currently online as well?
Title: Re: Block "Last Members WAS online"
Post by: whitesox on May 14, 2009, 05:27:16 PM
include (not sure, but its ok) and display the 10 last members
Title: Re: Block "Last Members WAS online"
Post by: JPDeni on May 14, 2009, 05:56:29 PM
To go into a php block:


global $db_prefix, $scripturl;

// How many do you want to display?
$limit = 10;

// Adjustment to time -- If the time displayed is not correct, enter how many hours it needs to be adjusted by.
$time_adjust = 0;

$result = db_query("SELECT realName, ID_MEMBER, lastLogin
FROM {$db_prefix}members
ORDER BY lastLogin DESC
LIMIT $limit", __FILE__, __LINE__);

echo '<table>';
while ($row = mysql_fetch_assoc($result)){
$time = $row['lastLogin'] + ($time_adjust * 3600);
echo '
<tr>
<td><a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></td>
<td>' . date('H:i',$time) . '</td>
</tr>';
}
echo '</table>';
mysql_free_result($result);


Added a variable -- $time_adjust -- to allow admins to adjust the time displayed.
Title: Re: Block "Last Members WAS online"
Post by: whitesox on May 14, 2009, 06:13:19 PM
absolut great !!! ok i have a elvispresley-site and he said:

THANK YOU VERY MUCH !!  :coolsmiley:
Title: Re: Block "Last Members WAS online"
Post by: Ianedres on May 14, 2009, 06:15:43 PM
Fast $foo from JPDeni. :o

Good work- and much better than what I had come up with initially.
::)
Title: Re: Block "Last Members WAS online"
Post by: JPDeni on May 14, 2009, 06:21:36 PM
:) Glad it worked for you, whitesox.

Thanks, Ianedres. There's almost always a number of ways to do something.
Title: Re: Block "Last Members WAS online"
Post by: whitesox on May 14, 2009, 06:57:55 PM
ok i think this is a good code, can any move 2 codesnippets ...
Title: Re: Block "Last Members WAS online"
Post by: JPDeni on May 14, 2009, 07:59:28 PM
Quotecan any move 2 codesnippets

I don't know what that means.
Title: Re: Block "Last Members WAS online"
Post by: whitesox on May 14, 2009, 08:35:52 PM
sry i mean can any move this thread to the forum "block code snippets"

sry 4 my bad english  ???
Title: Re: Block "Last Members WAS online"
Post by: JPDeni on May 14, 2009, 08:44:25 PM
I see. :-)

I'll change the topic title and move it.
Title: Re: [Block] Most recent visitors to site
Post by: whitesox on May 15, 2009, 12:18:28 PM
perfect and thx again :-)

not really perfect: i want the time +1 , can you help me?
Title: Re: [Block] Most recent visitors to site
Post by: whitesox on May 16, 2009, 02:12:29 PM
this code show not correct time (i think), i need time for germany (i think is gmt+1).

can any tell me how i change the code (i think with mktime, but i dont know how) ?
Title: Re: [Block] Most recent visitors to site
Post by: JPDeni on May 16, 2009, 02:48:17 PM
I changed the original code. I added in a place where you can enter the number of hours you want the time adjusted by.
Title: Re: [Block] Most recent visitors to site
Post by: whitesox on May 16, 2009, 05:06:18 PM
thank you very much!
Title: Re: [Block] Most recent visitors to site
Post by: JPDeni on May 16, 2009, 07:02:05 PM
:)
Title: Re: [Block] Most recent visitors to site
Post by: thefley on May 17, 2009, 01:44:12 AM
so you have a demo so we can see how it works?
Title: Re: [Block] Most recent visitors to site
Post by: JPDeni on May 17, 2009, 02:11:49 AM
Who are you asking? I don't because I don't want to put it on my live site and I don't have any real members of my testing site. If whitesox wants to give a link to his site, it would be nice.
Title: Re: [Block] Most recent visitors to site
Post by: whitesox on May 17, 2009, 07:49:41 AM
yes why not. here is my site - but its german :-)

http://www.elvisonline.de

and see screenshot  :up:
Title: Re: [Block] Most recent visitors to site
Post by: thefley on May 17, 2009, 02:16:43 PM
Quote from: JPDeni on May 17, 2009, 02:11:49 AM
Who are you asking? I don't because I don't want to put it on my live site and I don't have any real members of my testing site. If whitesox wants to give a link to his site, it would be nice.
sorry, I forgot to put whitesox name whom I was asking.....  thx WhiteSox.   I think I can use that block too.  MORE great work from JDP!!
Title: Re: [Block] Most recent visitors to site
Post by: whitesox on May 17, 2009, 06:59:44 PM
yes absolute great work from JPDeni  :up:
Title: Re: [Block] Most recent visitors to site
Post by: Ianedres on May 17, 2009, 07:05:36 PM
Much $foo from this JPDeni, yes. :coolsmiley:
Title: Re: [Block] Most recent visitors to site
Post by: Jessikard on May 19, 2009, 10:37:17 PM
 :up: great job
only one question - is it possible to adjust the font size ?

we need it smaller than now  ???
Title: Re: [Block] Most recent visitors to site
Post by: JPDeni on May 19, 2009, 10:42:00 PM
You can use the already-defined css "smalltext" size:


echo '<table class="smalltext">';


Or you can alter the font size just like you would on a regular html page, with inline css.
Title: Re: [Block] Most recent visitors to site
Post by: ElectricSquid on June 10, 2009, 05:28:46 AM
This is great, but if the users time goes back past 24 hours, the block shows no indicator of that.

example:

ElectricSquid        00:16
Cultural Infidel      22:46
DUFF                   22:02
Project84             21:01
HBMT                  18:25
phoenix               18:24
mopar65pa           17:58
Bogie                   01:07
dodgeman            22:44 <-----<< here's the flip into yesterday
intenseimages       08:52
Night Hawk           12:09
Raminator             01:18
BigDaddy_HD        21:05 <-----<< two days ago
+3$+                   20:58
dexetr30               11:49
D-100                   17:46
3jvj                      00:28
okiedrew               23:02 <-----<< three days ago
Mike_Mandaville     20:42


I think this mod would be GREAT if it showed the date as well

example:

ElectricSquid        00:16 6/10
Cultural Infidel      22:46 6/9
DUFF                   22:02 6/9
Project84             21:01 6/9
HBMT                  18:25 6/9
phoenix               18:24 6/9
mopar65pa           17:58 6/9
Bogie                   01:07 6/9
dodgeman            22:44 6/8
intenseimages       08:52 6/8
Night Hawk           12:09 6/8
Raminator             01:18 6/8
BigDaddy_HD        21:05 6/7
+3$+                   20:58 6/7
dexetr30               11:49 6/7
D-100                   17:46 6/7
3jvj                      00:28 6/7
okiedrew               23:02 6/6
Mike_Mandaville     20:42 6/6
Title: Re: [Block] Most recent visitors to site
Post by: JPDeni on June 10, 2009, 05:41:31 AM
Just change the date format in this part:


date('H:i',$time)


If you don't know how to adjust the date format, see this page (http://www.php.net/manual/en/function.date.php).
Title: Re: [Block] Most recent visitors to site
Post by: ElectricSquid on June 10, 2009, 05:46:33 AM
Thankyou.

Teach a man to fish, he eats for a lifetime, LOL
Title: Re: [Block] Most recent visitors to site
Post by: IchBin on June 10, 2009, 06:09:25 AM
Quote from: ∑Ã,£â„“Ã,¢ââ,¬Â Ã,®Ã,¡Ã,¢ Ã,§á»£Ã...³Ã,¡Ã,,‘ on June 10, 2009, 05:46:33 AM
Thankyou.

Teach a man to fish, he eats for a lifetime, LOL
/me Points at sig

:)
Title: Re: [Block] Most recent visitors to site
Post by: ElectricSquid on June 10, 2009, 06:53:19 AM
Quote from: IchBinâ„¢ on June 10, 2009, 06:09:25 AM
/me Points at sig

:)

Yup, I've come a long way from what you taught me a few years ago.
Quote from: JPDeni on June 10, 2009, 05:41:31 AM
Just change the date format in this part:


date('H:i',$time)


If you don't know how to adjust the date format, see this page (http://www.php.net/manual/en/function.date.php).

COOL, I have it looking good for my admin uses.
Using the "smalltext" class on the table, I have...



<tr>
<td align="left"><a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></td>
<td align="center" style="padding-right: 0px;">' . date('n/j',$time) . '</td>
<td align="right">' . date('g:i a',$time) . '</td>
</tr>



This gives the date and the time with am/pm and it all lines up nicely down the rows
( 6/10 1:39 am)



One last question, how do I go about making the admin invisible to users on this list?
I know it's something like...

            if (empty($context['admin']))
    - or -
            if (empty($context['user']['is_admin']))

...or something like that, but I don't know where to take it from there.

Title: Re: [Block] Most recent visitors to site
Post by: ElectricSquid on June 10, 2009, 07:39:35 AM
YEA!!
I think I figured out the answer to my question.

I used this bit of code as the if/else statement (for lack of a better term)


echo '<table width="100%" class="smalltext">';
while ($row = mysql_fetch_assoc($result)){
$time = $row['lastLogin'] + ($time_adjust * 3600);
echo '
<tr>
';

if ($row['ID_MEMBER'] == 1 )
echo '';

else

echo '
<td align="left"><a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></td>
<td align="center" style="padding-right: 0px;">' . date('n/j',$time) . '</td>
<td align="right">' . date('g:i a',$time) . '</td>
</tr>';
}
echo '</table>';
mysql_free_result($result);



... and my Admin username disappeared from the list without producing any errors in the error log or parse errors (the dreaded white screen of shame and doom).

Could one of you take a quick look over that if/else and tell me if it's truly correct?
Thanks!!
Title: Re: [Block] Most recent visitors to site
Post by: JPDeni on June 10, 2009, 02:18:25 PM
There's a number of ways to do it. If it was me, instead of


if ($row['ID_MEMBER'] == 1 )
echo '';

else


I would use


if ($row['ID_MEMBER'] <> 1 )


Cool that you worked it out for yourself, though.  :up:
Title: Re: [Block] Most recent visitors to site
Post by: starcad on September 13, 2009, 05:42:26 AM
Thanks JPDeni, I was looking for something like this.  Great Snippet