View Full Version : Help with call to database in postbit hook
Parker Clack
12-02-2007, 12:15 PM
I am trying to get a total of posts from the post table so that I can include that in my postbit template.
I have tried using the following in the postbit_start hook.
$postcount=$db->query_first("SELECT COUNT(*) AS posts FROM post WHERE postid AND post.visible=1");
$totalposts=$postcount[posts];
Which gets me an undefined call error in the postbit.php file.
Any ideas how to make this work?
Thanks,
Parker
TigerWare
12-02-2007, 03:13 PM
$postcount=$db->query_first("SELECT COUNT(*) AS posts FROM post WHERE postid AND post.visible=1");
$totalposts=$postcount[posts];
Which gets me an undefined call error in the postbit.php file.
Any ideas how to make this work?
Your query returns a number not an array.
Opserty
12-02-2007, 04:51 PM
Your query returns a number not an array. No it doesn't...at least last time I tried something similar it didn't :p
Are you sure you want to run that query on every postbit?
Best would be to run the query say at the start of the page (e.g. showthread_start) and then use the variable in the postbit. (Note: You may need to use the $_GLOBALS['postcount']['posts'] variable to access the data)
Dean C
12-02-2007, 04:53 PM
$thread[replycount] or $threadinfo[replycount]
One of those works, I can't remember which offhand. You don't need to run any queries.
Opserty
12-02-2007, 04:57 PM
Hang on...what postcount are you trying to get? The total forum postcount or the postcount for the thread?
Your SQL doesn't make much sense.
SELECT COUNT(*) AS posts FROM post WHERE postid AND post.visible=1
:confused:
If its the number of replies to the thread then the above post is correct.
TigerWare
12-02-2007, 04:58 PM
No it doesn't
That's a joke right?
--------------- Added 1196622101 at 1196622101 ---------------
That's a joke right?
Nope, guess not, I just checked the madness from the API. Excuse me whilst I go and eat my monitor.
Parker Clack
12-02-2007, 09:49 PM
It is to get the number of replies in a thread. Let say you have a thread with 10 total posts. I want to post the $totalpost count in that thread so it will say Post 1 of 10 or 5 of 10, etc.
Thanks,
Parker
Dean C
12-03-2007, 05:21 AM
$thread[replycount] then :) No queries necessary
Parker Clack
12-03-2007, 12:56 PM
Dean:
Thanks. To make the count correct though I created a hook in postbit_display_start and
used $postcount=$thread[replycount]+1;
Otherwise if there are 15 posts the 15th post shows up as Post 14 of 15.
Thanks again.
Dean C
12-04-2007, 05:23 AM
Better than running a query for every post though ;)
Parker Clack
12-04-2007, 12:20 PM
Dean:
You have that right!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.