View Full Version : hack to show the total posts/threads ever not just the totals in the database now?
jamie
05-08-2002, 09:18 AM
hello,
proably a simple thing but on my board lots of threads have been pruned. So on the forum home page is there anyway to show the total posts/threads ever posted not just the totals in the database now?
just so we don't miss out on the 500'000th post :o
Logician
05-08-2002, 12:14 PM
In index.php, changing the line:
$countposts=$DB_site->query_first('SELECT COUNT(*) AS posts FROM post');
to:
$countposts=$DB_site->query_first('SELECT postid AS posts FROM post ORDER BY postid DESC LIMIT 1' );
and line:
$countthreads=$DB_site->query_first('SELECT COUNT(*) AS threads FROM thread');
to:
$countthreads=$DB_site->query_first('SELECT threadid AS threads FROM thread ORDER BY threadid DESC LIMIT 1');
should do the trick! ;)
Enjoy! \\=^))
Logician
SFishy
05-09-2002, 03:54 AM
What if you already pruned and did the damage? How can you restore the count?
Ideas?
Thanks!
Logician
05-09-2002, 05:51 AM
@sFishy: The code above works and reliable even if you delete ALL records in your WHOLE database.. ;)
The logic that lies behind is that:
Your database tables give an id number to all records while saving them. This unique id number will be increased by 1 with every new record and since it's unique, even if you delete the record, same id # will never be assigned to a new record.
The original vbulletin code above counts the existing (undeleted) database records while calculating the message and threads numbers. However my code checks what the largest id number is in the table. If, say, it returns 4567, you are very likely to have less messages in your database, since some can be deleted in the past, but you can be sure that from day one to today, you created exactly 4567 threads whether some deleted or some exists.
See? ;)
Regards,
Logician
any way so it can be like this
Threads: XXX | Posts: xxx | Total Posts: XXX
Logician
05-09-2002, 08:36 AM
Originally posted by NerdNations
any way so it can be like this
Threads: XXX | Posts: xxx | Total Posts: XXX
Sure, why not:
Leave the original code as it is and add these 2 lines after them:
$count_maxx_posts=$DB_site->query_first('SELECT postid AS posts FROM post ORDER BY postid DESC LIMIT 1' );
$count_maxx_threads=$DB_site->query_first('SELECT threadid AS threads FROM thread ORDER BY threadid DESC LIMIT 1');
Now you can change your main page template and use these 2 variables $count_maxx_posts and $count_maxx_threads in anywhere or in any way you like..
Logician
Admin
05-09-2002, 09:30 AM
Logician: Just use MAX(postid) AS maxpostid, no need for the ORDER BY and LIMIT.
jamie
05-21-2002, 10:43 AM
thanks :) works great..not sure what firefly is on about (a better way to do it or something, but it went right over my head..) :)
CRego3D
08-31-2002, 09:53 PM
this worked GREAT .. is there a way to do it to the USERS as well ?
NTLDR
08-31-2002, 09:57 PM
Change in index.php:
$numbersmembers=$DB_site->query_first('SELECT COUNT(*) AS users,MAX(userid) AS max FROM user');
To:
$numbersmembers=$DB_site->query_first('SELECT userid AS users,MAX(userid) AS max FROM user');
That should do the job ;)
CRego3D
09-08-2002, 05:08 PM
no :(
I get this error
Database error in vBulletin 2.2.5:
Invalid SQL: SELECT userid AS users,MAX(userid) AS max FROM user
mysql error: Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause
mysql error number: 1140
CRego3D
09-13-2002, 05:18 PM
any ideas? :)
Logician
09-13-2002, 06:58 PM
Originally posted by CRego3D
any ideas? :)
$numbersmembers=$DB_site->query_first('SELECT MAX(userid) AS max FROM user');
CRego3D
09-14-2002, 05:04 AM
^^^^ That gives me users = 0 :D ..
Logician
09-17-2002, 07:08 AM
After adding the line, you should use this variable in your templates:
$numbersmembers['max']
CRego3D
09-17-2002, 07:44 PM
tried it .. still showed "0" :(
Logician
09-18-2002, 07:32 AM
If you add the line:
$numbersmembers=$DB_site->query_first('SELECT MAX(userid) AS max FROM user');
to your index.php and add
$numbersmembers['max']
to your forumhome template, it should work.. I tested it and it's working here..
wolfe
09-18-2002, 09:21 PM
Originally posted by Logician
Sure, why not:
Leave the original code as it is and add these 2 lines after them:
$count_maxx_posts=$DB_site->query_first('SELECT postid AS posts FROM post ORDER BY postid DESC LIMIT 1' );
$count_maxx_threads=$DB_site->query_first('SELECT threadid AS threads FROM thread ORDER BY threadid DESC LIMIT 1');
Now you can change your main page template and use these 2 variables $count_maxx_posts and $count_maxx_threads in anywhere or in any way you like..
Logician
i get this error on my index.php i use
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'
VBB 2.2.7
here is what i got in my index.php
// get total posts ever
$count_maxx_posts=$DB_site->query_first('SELECT postid AS posts FROM post ORDER BY postid DESC LIMIT 1' );
$count_maxx_posts=number_format($count_maxx_posts['posts']);
$count_maxx_threads=$DB_site->query_first('SELECT threadid AS threads FROM thread ORDER BY threadid DESC LIMIT 1');
$count_maxx_posts=number_format($count_maxx_thread s['threads']);
Logician
09-19-2002, 08:59 AM
Originally posted by wolfe
i get this error on my index.php i use
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'
I tested your code in vb.2.2.7 and it gave me no errors and successfully give me the numbers when I put them inside the forumhome template. Make sure you use the variables ($count_maxx_threads,$count_maxx_posts) only inside the templates and make sure you dont process these variables in your php script like adding them something etc. like
$count_maxx_threads=$count_maxx_threads+1000;
also make sure you dont get the error because of any other line in your code..
I strongly believe if you use only this code in index.php and $count_maxx_threads and $count_maxx_posts in forumhome template, you will not get ant errors..
Legacy
11-30-2002, 04:53 PM
NONE of this works for 2.2.8
for the MEMBERS part
have the Post counts working..need a working members count..600 members got removed acidentaly
[hhhh]
08-11-2003, 12:55 AM
Can it work on v 2.30?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.