vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Help with call to database in postbit hook (https://vborg.vbsupport.ru/showthread.php?t=164114)

Parker Clack 12-02-2007 12:15 PM

Help with call to database in postbit hook
 
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.

Code:

$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

Quote:

Originally Posted by Parker Clack (Post 1393474)
Code:

$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

Quote:

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.
[sql]SELECT COUNT(*) AS posts FROM post WHERE postid AND post.visible=1[/sql]
:confused:

If its the number of replies to the thread then the above post is correct.

TigerWare 12-02-2007 04:58 PM

Quote:

Originally Posted by Opserty (Post 1393594)
No it doesn't

That's a joke right?

--------------- Added [DATE]1196622101[/DATE] at [TIME]1196622101[/TIME] ---------------

Quote:

Originally Posted by TigerWare (Post 1393601)
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!


All times are GMT. The time now is 09:15 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01928 seconds
  • Memory Usage 1,731KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (11)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete