vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Displaying Threads on my Website Index (Update) (https://vborg.vbsupport.ru/showthread.php?t=206528)

Zero 3 02-25-2009 02:43 AM

Displaying Threads on my Website Index (Update)
 
Hi,

I just started a new website and switched over to vBulletin from phpBB. The last website I had, I was able to integrate forum posts within my site index. I used this code before: http://deceptive-logic.com/tutorial/php/topic with a little bit of tweaking. I want to do the same thing, but use vBulletin.

I forgot how to do a lot of coding, but I used to be decent with it (It's been 4 years since I last coded any time of script). If someone could please link me to a tutorial or be nice enough to place the required code I need, I would be very thankful. If you have any questions please PM me.

Thank you!
- Walter

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

Basically we want to integrate a particular forum/thread to show topics on our homepage. Our home page will be HTML.

Dismounted 02-25-2009 05:47 AM

Just include global.php, and run a query to fetch this data.
PHP Code:

$threads $vbulletin->db->query_read("
    SELECT *
    FROM " 
TABLE_PREFIX "thread
    WHERE forumid = X
    ORDER BY dateline DESC
    LIMIT 5
"
);

while (
$thread $vbulletin->db->fetch_array($threads))
{
    
// thread data is in $thread



Zero 3 02-25-2009 06:06 AM

can we get a little more clarification on this? How in fact do we run a query to fetch that data.

This is what we have so far:

Code:

LINE 50<?php include(Forum/global.php);
                        $threads = $vbulletin->db->query_read("
    SELECT *
    FROM " . blakecul_vbullet . "thread
    WHERE forumid = 2
    ORDER BY dateline DESC
    LIMIT 5
");

while ($thread = $vbulletin->db->fetch_array($threads))
{
    // thread data is in $thread
}  ?>

And receiving: Parse error: syntax error, unexpected T_GLOBAL in /home/blakecul/public_html/layoutsliced.php on line 50

Dismounted 02-25-2009 06:56 AM

You must use quotes, and include global.php like so: (This bit of code has been posted around a lot.)
PHP Code:

$curdir getcwd();
chdir('./forums');
require_once(
'./global.php');
chdir($curdir); 


Zero 3 02-25-2009 02:18 PM

Thank you! I think I'm a few steps short of getting it to work now since it's no longer stretching the tables and giving me errors. Now to get the threads to appear I assume I put something to display the threads here:

Code:


{
    // thread data is in $thread
}


This is the page in particular:

http://www.ydnfutc.com/layoutsliced.php

The big white content box on the right is where the threads would be appearing. What code do I use to display $thread

Dismounted 02-26-2009 05:46 AM

As mentioned, all the thread's data is in an array in $thread. You need to process this data to whatever way you want.

Zero 3 02-26-2009 04:21 PM

Okay, I did an array dump. I can't find the body of the post in that array (like the stuff I'm typing right now)

What I'm trying to do is go:

Quote:


"Title of thread here!" - By Walter

This is the body of the thread, the actual post itself.

What array do I need to get to gather the body of the post?

Alessandro68 02-26-2009 09:46 PM

Well I'm a newbie to php. How would you display the data in $thread in the following loop:

while ($thread = $vbulletin->db->fetch_array($threads))
{
// display data is in $thread
} ?>

Zero 3 02-27-2009 01:10 AM

Well, I did something called a dump, which shows you all the data inside the array. You need to replace this:

Code:

while ($thread = $vbulletin->db->fetch_array($threads))
{
// display data is in $thread
}

With this:

Code:

while ($thread = $vbulletin->db->fetch_array($threads))
{
      echo "<pre>";var_dump($thread);die;
}

It's going to list a bunch of items. You need to copy that and save that information in a text document or something (to refer back to later).

For me, I needed to gather the Title of the thread and the persons name who posted the thread, so it was in the format

"Thread Title!" - By UsernameHere

The two variables for that are ['title'] and ['postusername']. Once you have the variables you need, You can gather them by using an echo function:

Code:

while ($thread = $vbulletin->db->fetch_array($threads))
{
      echo $thread['title']." - By ".$thread['postusername']."<br>";
}

Basically, using the echo function, then following it with the array $thread and the variable ['title'] will give you this:

Code:

{
echo $thread['title']
}

Hope that helps! I went to http://www.phpfreaks.com to get help on this matter. They were very friendly and responded very quickly.

Alessandro68 02-27-2009 07:03 AM

Thank you veru much, appreciated !


All times are GMT. The time now is 05:56 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.01545 seconds
  • Memory Usage 1,742KB
  • 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
  • (6)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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