vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How do I extract all posts from a thread (https://vborg.vbsupport.ru/showthread.php?t=179742)

chrisjacob 05-19-2008 12:51 AM

How do I extract all posts from a thread
 
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); 



All times are GMT. The time now is 08:48 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.01004 seconds
  • Memory Usage 1,726KB
  • 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
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)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