Its just some conditionals so it only executes in a specific forum and only for the first post.
But its just using the globals object to execute a basic query.
Code:
$myrecs = $GLOBALS['vbulletin']->db->query_read("
SELECT
t.field1
FROM ".TABLE_PREFIX."table1 AS t
ORDER BY t.id DESC"
);
$mrows = $GLOBALS['vbulletin']->db->num_rows($myrecs );
$count = '(' . $mrows . ')' . ' Records Returned';
And then in the postbit template I just reference the $count variable to display it.
This is really just a test to get it working in the plugin as I have a very complex php file that will be running with the require_once function replacing this.