PDA

View Full Version : Showing posts/member count on non-forum HTML page


wii
11-16-2005, 01:34 PM
Showing posts and member count on non-forum HTML page.

Like this:

12116 forum members - 1104618 posts

wii
12-02-2005, 09:10 AM
Anyone? I would even pay a little (using paypal) to get this done !

Thanks

sabret00the
12-02-2005, 10:09 AM
// get total members
$numbersmembers=$db->query_first('SELECT COUNT(*) AS users FROM " . TABLE_PREFIX . "user');
$numbermembers = number_format($numbersmembers['users']);
// get total posts
$countposts=$db->query_first('SELECT COUNT(*) AS " . TABLE_PREFIX . "posts FROM post');
$totalposts = number_format($countposts['posts']);
//$countthreads=$db->query_first('SELECT COUNT(*) AS " . TABLE_PREFIX . "threads FROM thread');
//$totalthreads = number_format($countthreads['threads']);

echo $numbermembers . " forum members - " . $totalposts . " posts";


it's really not worth the money, but theirs the query you need to get the data, i commented out the data you may want but never requested.

wii
12-02-2005, 10:33 AM
Thanks a lot, which file do I need to include in my non-forum page to get this data ?

sabret00the
12-02-2005, 11:08 AM
include your forums' global.php

wii
12-02-2005, 12:00 PM
Thanks a lot...

I canĀ“t seem to get it right - in my HTML page I added a little include, like this:

<?php include("stats.php"); ?>

In the stats.php file I have this:

<?php
include_once('../forum/global.php');

// get total members
$numbersmembers=$db->query_first('SELECT COUNT(*) AS users FROM " . TABLE_PREFIX . "user');
$numbermembers = number_format($numbersmembers['users']);
// get total posts
$countposts=$db->query_first('SELECT COUNT(*) AS " . TABLE_PREFIX . "posts FROM post');
$totalposts = number_format($countposts['posts']);
//$countthreads=$db->query_first('SELECT COUNT(*) AS " . TABLE_PREFIX . "threads FROM thread');
//$totalthreads = number_format($countthreads['threads']);

echo $numbermembers . " forum members - " . $totalposts . " posts";

?>

What is wrong?

Thanks

sabret00the
12-02-2005, 02:03 PM
what happens when you run the stats.php?

wii
12-03-2005, 01:14 PM
Fatal error: Call to a member function query_first() on a non-object in D:\home\mysite\stats.php on line 5

Marco van Herwaarden
12-03-2005, 07:01 PM
Use $vbulletin->db->query_first instead of $db->query_first

wii
12-04-2005, 08:14 AM
Same result:

Fatal error: Call to a member function query_first() on a non-object in D:\home\mysite\stats.php on line 5

Marco van Herwaarden
12-04-2005, 09:24 AM
Try changing to:
<?php
chdir('../forum');
include_once('./global.php');
global $vbulletin; // Should not be needed

// get total members
$numbersmembers=$vbulletin->db->query_first('SELECT COUNT(*) AS users FROM " . TABLE_PREFIX . "user');

...etc, replacing $db by $vbulletin->db

wii
12-04-2005, 05:11 PM
Still the same result using this code:



<?php
chdir('../forum');
include_once('http://www.myforum.com/forum/global.php');

// get total members
$numbersmembers=$vbulletin->db->query_first('SELECT COUNT(*) AS users FROM " . TABLE_PREFIX . "user');
$numbermembers = number_format($numbersmembers['users']);
// get total posts
$countposts=$vbulletin->db->query_first('SELECT COUNT(*) AS " . TABLE_PREFIX . "posts FROM post');
$totalposts = number_format($countposts['posts']);
//$countthreads=$vbulletin->db->query_first('SELECT COUNT(*) AS " . TABLE_PREFIX . "threads FROM thread');
//$totalthreads = number_format($countthreads['threads']);

echo $numbermembers . " forum members - " . $totalposts . " posts";

?>



I would still even pay for a working code, so I can include these stats in my website (not forum).

Thanks

Anyone? I would even pay a little (using paypal) to get this done !

Thanks

Marco van Herwaarden
12-04-2005, 06:05 PM
replace:
include_once('http://www.myforum.com/forum/global.php');
With:require_once('./global.php');

And with the above code, error message is the same? Even the linenumber?

wii
12-05-2005, 05:40 AM
Now I get an SQL error:

Invalid SQL:
SELECT COUNT(*) AS users FROM " . TABLE_PREFIX . "user;

Marco van Herwaarden
12-05-2005, 05:57 AM
Please post your current script and the full error message.

wii
12-05-2005, 07:20 AM
Ok, the script:



<?php
chdir('../forum');
require_once('./global.php');

// get total members
$numbersmembers=$vbulletin->db->query_first('SELECT COUNT(*) AS users FROM " . TABLE_PREFIX . "user');
$numbermembers = number_format($numbersmembers['users']);
// get total posts
$countposts=$vbulletin->db->query_first('SELECT COUNT(*) AS " . TABLE_PREFIX . "posts FROM post');
$totalposts = number_format($countposts['posts']);
//$countthreads=$vbulletin->db->query_first('SELECT COUNT(*) AS " . TABLE_PREFIX . "threads FROM thread');
//$totalthreads = number_format($countthreads['threads']);

echo $numbermembers . " forum members - " . $totalposts . " posts";

?>



The error - removed link (private forum)



Database error in vBulletin 3.5.1:

Invalid SQL:
SELECT COUNT(*) AS users FROM " . TABLE_PREFIX . "user;

MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '" . TABLE_PREFIX . "user' at line 1
Error Number : 1064
Date : Monday, December 5th 2005 @ 10:19:57 AM
Script : http://www.myforum.com/beta/stats.php
Referrer :
IP Address : XX.XX.XX.XX
Username : wii
Classname : vB_Database

Marco van Herwaarden
12-05-2005, 08:40 AM
$numbersmembers=$vbulletin->db->query_first('SELECT COUNT(*) AS users FROM " . TABLE_PREFIX . "user');
replace by:
$numbersmembers=$vbulletin->db->query_first("SELECT COUNT(*) AS users FROM " . TABLE_PREFIX . "user");

Do the same for the other query (SDon't use single quotes there).

wii
12-07-2005, 11:11 AM
Ok, I got the include to work on the page, but which include is best to use for this?

include()
require()
include_once()
require_once()

I?m using require currently.

But the post count is between 10-13 more than on the forum (seems to change once in a while), anyway to fix this?

Is it possible to modify the script, so it uses the same as index.php to count the posts?



// get total threads & posts from the forumcache
$totalthreads = 0;
$totalposts = 0;
if (is_array($vbulletin->forumcache))
{
foreach ($vbulletin->forumcache AS $forum)
{
$totalthreads += $forum['threadcount'];
$totalposts += $forum['replycount'];
}
}
$totalthreads = vb_number_format($totalthreads);
$totalposts = vb_number_format($totalposts);

// get total members and newest member from template
$numbermembers = vb_number_format($vbulletin->userstats['numbermembers']);

Marco van Herwaarden
12-07-2005, 11:26 AM
require_once is mostly the correct way.

wii
12-07-2005, 04:27 PM
Thanks

Dark Riku
12-08-2005, 06:07 AM
Thanks for this, i converted like 10 hacks i had from older versions. =)