Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6608953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:39:52+00:00 2026-05-25T19:39:52+00:00

I want to create a script that counts threads words’ count in a vBulletin

  • 0

I want to create a script that counts threads words’ count in a vBulletin forum. Bascially, I want to pull that database from the mysql database, and play with it. I don’t have experience working with vBulettin, so I’m thinking of two ways:

  1. Does vBulletin provides API to handle database stuff. (Allow me to grab all the threads content, and URLs). I’m almost sure there is, a link where to start?

  2. Is there a solution doing this without the interferance of vBulletin. This means grab the data manually from the mysql database and do stuff the typical way.

I’ll prefer the second method if the vBulettin learning curve is too steep. Thanks for the advice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:39:52+00:00Added an answer on May 25, 2026 at 7:39 pm

    Is this for vBulletin 3 or 4?

    I mostly work with vB3, and the quickest way to include all of the vBulletin resources is to create a new php file in your forums directory with the following code.

    <?php
    error_reporting(E_ALL & ~E_NOTICE & ~8192);
    require_once('./global.php');
    var_dump($vbulletin);
    

    That $vbulletin variable is the registry object that contains just about everything you’re ever going to need, including the database connection and it’s read and write functions, userinfo data, cleaned _POST and _REQUEST values, and a lot more (phrases, session data, caches, etc).

    There are 4 database functions you’ll use the most.

    • $vbulletin->db->query_read() // fetch more than one row
    • $vbulletin->db->fetch_array() // converts the query_read returned data into an array
    • $vbulletin->db->query_first() // fetches a single row
    • $vbulletin->db->query_write() // update, insert or delete rows, tables, etc.

    query_read is what you would use when you expect more than one result that you intend to loop through. For example, if you wanted to count all the words in a single thread, you would would need to query the post table with the threadid, loop through each post in that thread and count all the words in the message.

    Note: “TABLE_PREFIX” is a constant set in config.php. It’s important to always prepend the table name with that constant in case other forums decide to prefix their tables.

    <?php
    error_reporting(E_ALL & ~E_NOTICE & ~8192);
    require_once('./global.php');
    
    $threadid = 1;
    
    // fetch all post from a specfic thread
    $posts = $vbulletin->db->query_read("
        SELECT pagetext 
          FROM " . TABLE_PREFIX . "post 
         WHERE threadid = $threadid
    ");
    
    /**
     * Loop through each post.
     *
     * Here we use the "fetch_array" method to convert the MySQL data into 
     * a useable array. 99% of the time you'll use "fetch_array" when you 
     * use "query_read".
     *
     * $post will contains the post data for each loop. In our case, we only
     * have "pagetext" avaliable to use since that's all we told MySQL we needed
     * in our query. You can do SELECT * if you want ALL the table data.
     */
    while ($post = $vbulletin->db->fetch_array($posts)) {
        $totalWords = $totalWords + str_word_count($post['pagetext']);
    }
    
    /**
     * Print the total number of words this thread contains.
     *
     * The "vb_number_format" is basically wrapper of php's "number_format", but
     * with some vBulletin extras. You can visit the /includes/functions.php file
     * for all the functions available to you. Many of them are just convenient 
     * functions so you don't have to repeat a lot of code. Like vBDate(), or 
     * is_valid_email().
     */
    echo sprintf("Thread ID %i contains %s words", $threadid, vb_number_format($totalWords));
    

    The query_first function is what you would use when you need to fetch a single row from the database. No looping required or anything like that. If, for instances, you wanted to fetch a single user’s information from the database – which you don’t need a query for, but we’ll do it as an example – you would use something like this.

    <?php
    error_reporting(E_ALL & ~E_NOTICE & ~8192);
    require_once('./global.php');
    
    $userid = 1;
    $user = $vbulletin->db->query_first("
        SELECT *
          FROM " . TABLE_PREFIX . "user
         WHERE userid = $userid
    ");
    
    echo sprintf("Hello, %s. Your email address is %s and you have %s posts",
        $user['username'], 
        $user['email'], 
        vb_number_format($user['posts'])
    );
    

    Lastly, if you wanted to update something in the database, you would use “query_write“. This function is pretty straight forward. This function just takes any MySQL update insert or delete query. For example, if I needed to update a user’s yahoo id, you would do.

    <?php
    error_reporting(E_ALL & ~E_NOTICE & ~8192);
    require_once('./global.php');
    
    $userid = 1;
    $update = $vbulletin->db->query_write("
        UPDATE " . TABLE_PREFIX . "user
           SET yahoo = 'myYahooID@yahoo.com'
         WHERE userid = $userid
    ");
    
    if ($update) {
        $userinfo = fetch_userinfo($userid);
        echo sprintf("Updated %s yahoo ID to %s", $userinfo['username'], $userinfo['yahoo']);
    }
    

    Hopefully this will help you get started. I would recommend using vBulletin 3 for a little while until you’re comfortable with it. I think it’ll be easier on you. Most of this will translate to vBulletin 4 with some tweaking, but that code base is not as friendly to new comers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an SQL script that creates a database. Right now, I
I want to create a script that parses or makes sense of apache's error
I have a script that create a new div element. Then, I want to
I want to create some kind of AJAX script or call that continuously will
Is it possible to change current directory from a script? I want to create
I want create a ruby script that I can run on the command line
I want to create a single shape file from multiple mxd's that have multiple
I want to create a script that does the following: When answering questions via
I want to create a timer in PHP that will count down every second.
I want to create a script that will set the file associations for mostly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.