Need to extract all the posts allocated to a thread and store this information in an array.
I can use the following to fetch thread info for 1 thread:
PHP Code:
$threadinfo = fetch_threadinfo($threadid);
$threadinfo stores an array with the following details (and more):
threadid : 29
title : Extract this thread
firstpostid : 39
lastpostid : 43
lastpost : 1211157483 -- I don't know what this number is for?
forumid : 3
...
And I can use the following to fetch post info for 1 post:
PHP Code:
$postinfo = fetch_postinfo($postid);
$postinfo stores an array with the following details (and more):
postid : 41
threadid : 29
parentid : 40
username : test
userid : 2
title : 3rd post from Test User
dateline : 1211155226
pagetext : This is a 3rd post
...
Q1. The trouble I'm having is fetching ALL posts that belong to a thread.
Q2. Can I do this using vB Data Managers (is there an existing DM for this?) or do I need to query the database via the vBulletin DB Class (
https://vborg.vbsupport.ru/showthrea...ht=fetch_field
)
Q3 - Heres my proposed solution. Please pick it to bits - security, speed, stupidity, etc..
Currently I'm thing of using Data Managers and looping through posts as follows:
1) fetch the thread_info 1st and find out it's LAST post ID and FIRST Post ID
2) fetch the post_info for the LAST post and save it's details to an array ($allposts)
3) use the LAST post's "parentid" to find the next post to look for.
4) repeat this process until the Post's "postid" == the Thread's "firstpostid"
--------------- Added [DATE]1211242198[/DATE] at [TIME]1211242198[/TIME] ---------------
This seems to work well:
PHP Code:
chdir('/var/www/vhosts/example.net.au/subdomains/abc/httpdocs/forum');
require_once('./global.php');
$tThreadId = 29;
echo "<h2>Thread Posts for Thread ID: $tThreadId</h2>";
$result_set = $vbulletin->db->query_read("SELECT * FROM " . TABLE_PREFIX . "post WHERE threadid = $tThreadId");
while ($result = $vbulletin->db->fetch_array($result_set))
{
echo "<h3>Post ID: ".$result['postid']."</h3>";
reset($result);
while (list($key, $value) = each ($result))
{
echo "$key : $value <br />";
}
}
$vbulletin->db->free_result($result_set);