PDA

View Full Version : Number of Posts in Current Forum Only


apfeifer
11-03-2001, 10:00 PM
Hack: Number of Posts in Current Forum Only
Version of vB: 2.2.0, although may work on earlier versions but not tested
Current Version: 1.0.0
Description: This hack shows how many posts a user has in the forum that the post you are viewing is in

Requested by Bald Bouncer.

MarkB
11-04-2001, 09:26 PM
Does this override the current post count display? Or is it displayed seperately? :)

MarkB
11-04-2001, 09:33 PM
Ok, I tried it, and the following error came up when viewing a thread:

Fatal error: Call to a member function on a non-object in /home/ultimatm/public_html/forum/admin/functions.php on line 275

apfeifer
11-04-2001, 09:34 PM
It is displayed below it, I'll attach a screenshot of it.

Screenshot:

apfeifer
11-04-2001, 09:38 PM
Ahh! Thank you! I forgot to add a step:

Find:

global $showdeficon,$displayemails,$enablepms,$allowsigna tures,$wordwrap,$dateformat,$timeformat,$logip,$re placewords,$postsperday,$avatarenabled,$registered dateformat,$viewattachedimages;

After that add:

global $DB_site;

Sorry about that! I'll add it into the documentation right away.

:cool:

Scott MacVicar
11-04-2001, 09:40 PM
could kinda be bad, if a user has made 300 posts in the forums then thats 300 extra queries per post, you should cache it.

if (!isset($posttotal[$post[userid]])) {
$grabthreadids=$DB_site->query("SELECT threadid FROM post WHERE post.userid='$post[userid]' AND post.visible=1");

$post[thisforumonly] = "0";

while ($getcount=$DB_site->fetch_array($grabthreadids)) {
$checkforumid=$DB_site->query_first("SELECT forumid FROM thread WHERE threadid=$getcount[threadid] AND thread.visible=1");
if ($checkforumid[forumid] == $forum[0]) {
$post[thisforumonly]++;
}
}
$posttotal[$post[userid]] = $post[thisforumonly];
}
else {
$post[thisforumonly] = $posttotal[$post[userid]];
}

apfeifer
11-04-2001, 09:44 PM
Yeah, in the other thread (the request) I mentioned how this had a lot of queries in it. I actually had tried something almost identical to what you did, but it wasn't working so I decided to release it so people had something to use and play with that later. Is that chunk of code you posted 100% sure to work? If so I'll add it in, with your permission, of course.

:cool:

Scott MacVicar
11-04-2001, 09:46 PM
I never tested it, just off the top of my head. You should test it first and see if it works.

apfeifer
11-04-2001, 09:47 PM
Will do, let me finish documenting this other hack and I will do it ASAP.

:cool:

MarkB
11-04-2001, 09:49 PM
The hack works for me now, and I await to see if this caching bizzo works too :cool:

JJR512
11-05-2001, 06:27 AM
OK, I tried this hack. While it does work, it also adds a very noticable amount of extra time to open a thread. The more posts in a thread (or I guess more accurately, the more unique people to post in a thread), the worse it gets. Quite noticably.

Please let us know if that cacheing bit works good, after its tested. :)

Bald Bouncer
11-05-2001, 08:36 AM
you made me very happy matey :D

apfeifer
11-05-2001, 11:08 AM
Originally posted by JJR512
OK, I tried this hack. While it does work, it also adds a very noticable amount of extra time to open a thread. The more posts in a thread (or I guess more accurately, the more unique people to post in a thread), the worse it gets. Quite noticably.

Please let us know if that cacheing bit works good, after its tested. :)

Yeah, right now this takes TON'S of queries to do. I am going to add some more stuff to it, including the cache bit, and that should make it better. At the end I should be able to just do one COUNT(*) to get the number, which would greatly improve the speed.

:cool:

Admin
11-05-2001, 11:15 AM
SELECT COUNT(postid) AS posts FROM post LEFT JOIN thread USING (threadid) WHERE thread.forumid='1' AND post.userid='xx'
Gets you the number of posts user #xx made in forum #1.
(btw, this is for one forum only, not from sub forums as well)

But still this is another query for each post, so in a thread with 30 posts per page you will have another 30 queries.

Bald Bouncer
11-06-2001, 08:45 AM
is there a way for this hack to count posts made in more than one forum?

SgtSling
11-27-2001, 05:06 AM
bump

Joshua Clinard
03-24-2002, 06:31 PM
Did anyone ever get this cache thing working?

N9ne
06-23-2002, 12:37 AM
yeah?