X viewing forums

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Get Involved
wiseman1161980
Registered User
Posts: 111
Joined: Wed Oct 04, 2006 5:58 am
Location: Missouri, USA
Contact:

X viewing forums

Post by wiseman1161980 » Tue Oct 23, 2007 12:46 am

I think there was a mod in phpbb2, but I'd like to see a mod showing how many people are viewing a certain forum next to the forum name on board index.

Image

wiseman1161980
Registered User
Posts: 111
Joined: Wed Oct 04, 2006 5:58 am
Location: Missouri, USA
Contact:

Re: X viewing forums

Post by wiseman1161980 » Sun Jun 22, 2008 9:09 am

I think I'm due for a bump :lol:

anyone?

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: X viewing forums

Post by tommekemc » Sun Jun 22, 2008 12:42 pm

okay, I did it like this:
in includes/functions_display.php find:

Code: Select all

		// Output moderator listing ... if applicable
add before:

Code: Select all

$viewers_mysql=$db->sql_query("SELECT `session_forum_id` 
		FROM ". SESSIONS_TABLE ." 
		WHERE `session_last_visit`>".(time()-($config['load_online_time']*60)));
		$forum_viewers=0;
		while($viewers_mysql_row=$db->sql_fetchrow($viewers_mysql)){
			if($viewers_mysql_row['session_forum_id']==$row['forum_id']){
				$forum_viewers++;
			}
		}
find:

Code: Select all

			'S_IS_CAT'			=> false,
add before:

Code: Select all

			'FORUM_VIEWERS'		=> $forum_viewers,
in styles/YOUR STYLE/forumlist_body.html
add this code where you want the text to come:

Code: Select all

<b> ({forumrow.FORUM_VIEWERS} viewing)</b>
Last edited by tommekemc on Mon Jun 23, 2008 9:30 pm, edited 6 times in total.
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

wiseman1161980
Registered User
Posts: 111
Joined: Wed Oct 04, 2006 5:58 am
Location: Missouri, USA
Contact:

Re: X viewing forums

Post by wiseman1161980 » Sun Jun 22, 2008 6:06 pm

I tried that and it threw
[phpBB Debug] PHP Notice: in file /includes/functions_display.php on line 364: mysql_fetch_row(): supplied argument is not a valid MySQL result resource

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: X viewing forums

Post by tommekemc » Sun Jun 22, 2008 7:28 pm

my mistake, had some of my old code in there, it works on my forum :)
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

wiseman1161980
Registered User
Posts: 111
Joined: Wed Oct 04, 2006 5:58 am
Location: Missouri, USA
Contact:

Re: X viewing forums

Post by wiseman1161980 » Sun Jun 22, 2008 8:15 pm

awesome, works like a charm.

Thanks a million... again. :D

User avatar
darkonia
Registered User
Posts: 1901
Joined: Tue May 13, 2008 1:10 pm
Location: Munich, Germany
Contact:

Re: X viewing forums

Post by darkonia » Mon Jun 23, 2008 8:30 pm

great little mini addon...thx :D
MMOG-Heaven - Das Gaming Portal
Community bedeutet Gleichgesinnte finden - MMOG-Heaven ist Deine Community! Von Spielern für Spieler bietet Dir dieses Portal genau das, was ein Spieler braucht. Bleibe ständig informiert, finde die neuesten MMORPGs, oder suche die frischesten News aus der Welt des Online Gamings - dieses und vieles mehr erwartet Dich auf MMOG-Heaven.

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: X viewing forums

Post by tommekemc » Mon Jun 23, 2008 8:39 pm

well, I did a lidle patch, for the ones already having this mod:
some users were still 'browsing' when they already showed offline...
and more patching to come :p
Last edited by tommekemc on Mon Jun 23, 2008 9:22 pm, edited 3 times in total.
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: X viewing forums

Post by tommekemc » Mon Jun 23, 2008 8:58 pm

delete me, accident...
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

User avatar
darkonia
Registered User
Posts: 1901
Joined: Tue May 13, 2008 1:10 pm
Location: Munich, Germany
Contact:

Re: X viewing forums

Post by darkonia » Mon Jun 23, 2008 9:01 pm

lol whats up dude... :shock:
MMOG-Heaven - Das Gaming Portal
Community bedeutet Gleichgesinnte finden - MMOG-Heaven ist Deine Community! Von Spielern für Spieler bietet Dir dieses Portal genau das, was ein Spieler braucht. Bleibe ständig informiert, finde die neuesten MMORPGs, oder suche die frischesten News aus der Welt des Online Gamings - dieses und vieles mehr erwartet Dich auf MMOG-Heaven.

User avatar
Highway of Life
Former Team Member
Posts: 6048
Joined: Wed Feb 02, 2005 5:41 pm
Location: Seattle, WA
Name: David Lewis
Contact:

Re: X viewing forums

Post by Highway of Life » Mon Jun 23, 2008 9:19 pm

The code posted has several errors and I don't recommend using it, as-is.

Firstly, it is running an SQL Query inside of a loop, this is never a good idea, you’d end up increasing the load on both the web server and most especially the database server by increasing the SQL queries astronomically and unnecessarily.

Second, you’re using hard-coded mysql_* functions, this is again, a big no-no for code within phpBB3. It should be using the DBAL (Database Abstraction Layer) .

Thirdly, you’re hard-coding the table prefix, so a user who has a table prefix other than 'phpbb_', this code will not work for them.

Fourth, it could be done using a single fetchfield query without the unnecessary extra rows:

Code: Select all

$sql = 'SELECT COUNT(session_id) AS forum_viewers
FROM ' . SESSIONS_TABLE . '
WHERE session_forum_id = ' . (int) $row['forum_id'] . ' AND session_last_visit >= ' . (time() - $config['load_online_time']);
$result = $db->sql_query($sql);
$forum_viewers = $db->sql_fetchfield('forum_viewers'); 
Note that this is only a demonstration and is no way intended to be used live, it is still running the query from the loop, but is only meant to demonstrate what the query should look like.
The phpBB Weekly Podcast - Discussing the developments of phpBB4 and beyond.

New to phpBB3? Want to learn about programing?
Visit phpBB Academy at StarTrekGuide to learn how.

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: X viewing forums

Post by tommekemc » Mon Jun 23, 2008 9:21 pm

I know, I'm editing it at this very moment :)
generated a load of bugs while making it as you want :p
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

tommekemc
Registered User
Posts: 457
Joined: Wed May 14, 2008 6:36 pm
Location: Belgium
Contact:

Re: X viewing forums

Post by tommekemc » Mon Jun 23, 2008 9:28 pm

1st thing: I found out that fetchfield only fetches the data once (hereby only calculating the data for the 1st forum, so I had to place it inside the loop.)
2nd: just worked that out
3rd: worked away, updating :)
4th: sorry, I'm used to working with mysql in a completely different way...

and last: I'm only trying to help... :(
my sig
my projects

images deleted because of the 6kb (wtf?) rule...

User avatar
Highway of Life
Former Team Member
Posts: 6048
Joined: Wed Feb 02, 2005 5:41 pm
Location: Seattle, WA
Name: David Lewis
Contact:

Re: X viewing forums

Post by Highway of Life » Mon Jun 23, 2008 9:53 pm

tommekemc wrote:1st thing: I found out that fetchfield only fetches the data once (hereby only calculating the data for the 1st forum, so I had to place it inside the loop.)
Yes, of course... it would only work on a per-forum basis if you use a count, therefore, you’d take an array of the forum_ids and do the following query...

($forum_ary is your array of forum ids.)

Code: Select all

$sql = 'SELECT session_forum_id, COUNT(session_forum_id) AS forum_visitors
FROM ' . SESSIONS_TABLE . '
WHERE ' . $db->sql_in_set('session_forum_id', $forum_ary) . '
    AND session_last_visit >= ' . (time() - $config['load_online_time']) . '
GROUP BY session_forum_id';  
Now just match up $row['forum_visitors'] with $row['session_forum_id'] to give you a count of total visitors within each forum.
tommekemc wrote:and last: I'm only trying to help... :(
And that’s okay, but if you’re not sure if your method is good, it might be a good idea to put a disclaimer on there, as other non-coders are going to trust that you’re going to provide them with good, secure, and optimised code, which it wasn’t and I therefore had to come out with a stern warning not to use the code until it is perfected.
Not trying to pick on you, just ensuring people were not going to use broken code. No worries. :)
The phpBB Weekly Podcast - Discussing the developments of phpBB4 and beyond.

New to phpBB3? Want to learn about programing?
Visit phpBB Academy at StarTrekGuide to learn how.

wiseman1161980
Registered User
Posts: 111
Joined: Wed Oct 04, 2006 5:58 am
Location: Missouri, USA
Contact:

Re: X viewing forums

Post by wiseman1161980 » Mon Jun 23, 2008 10:18 pm

tommekemc wrote:well, I did a lidle patch, for the ones already having this mod:
some users were still 'browsing' when they already showed offline...
and more patching to come :p
If your gonna put the time into this, why not start a topic in mods in development and become a modder? :mrgreen:

I know several people would like to use this. I know I appreciate it.

Locked

Return to “[3.0.x] MOD Requests”