Log in

View Full Version : How to Read Number of Posts in Thread From Database?


nogerorob
07-13-2004, 05:34 AM
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/testing/php/php2/test.php
which is based on this code: http://www.weeklydavespeak.com/testing/php/php2/test_php.txt

Suppose I know the thread number, i.e. http://www.weeklydavespeak.com/forums/showthread.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

Andreas
07-13-2004, 05:38 AM
As you are using the vBulletin backend you can use it's library functions:


$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].

nogerorob
07-13-2004, 03:07 PM
As you are using the vBulletin backend you can use it's library functions:


$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

NTLDR
07-13-2004, 03:20 PM
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.

nogerorob
07-14-2004, 12:59 AM
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:

nogerorob
07-15-2004, 05:41 AM
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.


<?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

Xenon
07-15-2004, 04:54 PM
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)

nogerorob
07-16-2004, 04:24 AM
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

$threadinfo = fetch_threadinfo(2);
Has to be:
$threadWanted = 2;
$threadinfo = fetch_threadinfo($threadWanted);


So my final code I used to accomplish the comment code was the following:

// ################################################## #####################
// ####################### 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/testing/php/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 (http://www.weeklydavespeak.com/news/Dave_Politics_062204.shtml)

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

rob

nogerorob
07-21-2004, 11:09 PM
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