Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-13-2004, 05:34 AM
nogerorob nogerorob is offline
 
Join Date: Jun 2004
Location: Portland, OR
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to Read Number of Posts in Thread From Database?

Hello,

I want to connect content on my main page to discussions on my vBB. What I'd like to do is have a "Comment on This (x Comments)" where x is equal to the number of posts in a given thread.

I've learned how to create a basic vB powered page: http://www.weeklydavespeak.com/testi.../php2/test.php
which is based on this code: http://www.weeklydavespeak.com/testi...2/test_php.txt

Suppose I know the thread number, i.e. http://www.weeklydavespeak.com/forum...thread.php?t=2

This appears to be Thread 2, how do i query the database to get the current number of posts in there?

Thanks ya'll.

Rob
Reply With Quote
  #2  
Old 07-13-2004, 05:38 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

As you are using the vBulletin backend you can use it's library functions:

PHP Code:
$threadinfo fetch_threadinfo(2); 
This will give you an array which contains all necessary information about Thread ID 2. If you want to know how many replies it does have use $threadinfo[replycount].
Reply With Quote
  #3  
Old 07-13-2004, 03:07 PM
nogerorob nogerorob is offline
 
Join Date: Jun 2004
Location: Portland, OR
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by KirbyDE
As you are using the vBulletin backend you can use it's library functions:

PHP Code:
$threadinfo fetch_threadinfo(2); 
This will give you an array which contains all necessary information about Thread ID 2. If you want to know how many replies it does have use $threadinfo[replycount].
Hey KirbyDE,

Thanks a lot--that helps a bunch.

Where can I find a list of vBulletin's other library functions?

Rob
Reply With Quote
  #4  
Old 07-13-2004, 03:20 PM
NTLDR's Avatar
NTLDR NTLDR is offline
Coder
 
Join Date: Apr 2002
Location: Bristol, UK
Posts: 3,644
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Take alook in the various files in your includes folder, all the files in the format functions_X.php (and functions.php) contain all the main vBulletin fuinctions, the X represents they type of functions the file contains, calendar, user etc.
Reply With Quote
  #5  
Old 07-14-2004, 12:59 AM
nogerorob nogerorob is offline
 
Join Date: Jun 2004
Location: Portland, OR
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by NTLDR
Take alook in the various files in your includes folder, all the files in the format functions_X.php (and functions.php) contain all the main vBulletin fuinctions, the X represents they type of functions the file contains, calendar, user etc.

I'll have a look. Thank you.

rob :alien:
Reply With Quote
  #6  
Old 07-15-2004, 05:41 AM
nogerorob nogerorob is offline
 
Join Date: Jun 2004
Location: Portland, OR
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,

I need a bit of help understanding how to place this code. I'm a bit new at this, so thank you for your patience.

The code you gave me looks like you're assigning an array of data to the variable $threadinfo. I looked and found that the fetch_threadinfo() function appears in the functions.php document.

I get a Fatal error: Call to undefined function: fetch_threadinfo() when I attempt to make this assignment in my test.php file.

Code:
<?php 
chdir("../../../forums");
$threadinfo = fetch_threadinfo(2);

// ####################### SET PHP ENVIRONMENT ########################### 
error_reporting(E_ALL & ~E_NOTICE); 

<snip>
?>
Where should I place the above code in order to get the results I mentioned previously?

I would expect that this would resolve correctly leaving $threadinfo to contain the aforementioned array of data. My next step would be to print just the $threadinfo[replycount] out in the php file somehow. I'd welcome suggestions on how to accomplish this as well.


To be abundantly clear of my intentions:

I want to create a function that outputs the number of responses to a given thread in a forum. I plan to have this appear in a line of text "(x comments)" and then include() the output of this php file in larger html/php file (which contains the news story pictures etc.)



Again, thank you for the help.

rob
Reply With Quote
  #7  
Old 07-15-2004, 04:54 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you should require global.php in your script, then it will create all the major functions you may need

(look at any vbulletin code file, to see what should be on the file's beginning)
Reply With Quote
  #8  
Old 07-16-2004, 04:24 AM
nogerorob nogerorob is offline
 
Join Date: Jun 2004
Location: Portland, OR
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Xenon
you should require global.php in your script, then it will create all the major functions you may need

(look at any vbulletin code file, to see what should be on the file's beginning)

Ah. Thanks, that worked.

But then I got a fatal error saying that I can't pass a variable as a reference. I hacked at it and finally figured out that

Code:
$threadinfo = fetch_threadinfo(2);
Has to be:
Code:
 $threadWanted = 2;
$threadinfo = fetch_threadinfo($threadWanted);
So my final code I used to accomplish the comment code was the following:
Code:
// #######################################################################
// ####################### Begin My Page #################################
$comment_news = "Comment on this News";
$comment_article = "Comment on this Article";

//  Thread ID 
$threadWanted = 2;
//  URL to Thread Top
$thread_URL = 'http://www.weeklydavespeak.com/forums/showthread.php?t=2';

//  Pull array of thread info from database
$threadinfo = fetch_threadinfo($threadWanted); 

//  Output Text and Hyperlink
echo "<a href='$thread_URL'>";
echo "$comment_news";
echo "</a>";

echo " ($threadinfo[replycount]", ' Comments)';
echo "<br>";
// ####################### End My Page ###################################
// #######################################################################
You can view the working page here: http://www.weeklydavespeak.com/testi.../php2/test.php

Thanks to those of you who took the time to help me along. This is really my first php work, and first experience doing anything with vB. I'd welcome comments on the above code or other suggestions.

My next step is to convert my SSI/SHTML pages into php and add lines like this to my story pages i.e.: The news article attached to the above code

Oh, and overhall my forum's look and about a dozen other things.

rob
Reply With Quote
  #9  
Old 07-21-2004, 11:09 PM
nogerorob nogerorob is offline
 
Join Date: Jun 2004
Location: Portland, OR
Posts: 82
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I posted a How To on this, along with my completed script here: https://vborg.vbsupport.ru/showthread.php?t=67469

Thanks for your help, peeps.

rob
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:18 PM.


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.03859 seconds
  • Memory Usage 2,251KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (2)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete