View Full Version : How could I display total # of subscribers? Help Please
TrickyD
09-09-2005, 04:01 AM
I use the paid subscriptions feature to help cover a majority of the financial burden my forum generates and I'd like to be able to display somewhere in the header the total number of subscribers.
Basically I'd like to have just a small little space say
"Current Subscribers X, Goal 120"
Where X is pulled automatically like it is from the Subscriptions Manager tab in the AdminCP
If anyone can help on this one I'd greatly appreciate it. Thanks!
TrickyD
09-12-2005, 06:33 PM
Can any of you code geniuses out there help me out with this?
Andreas
09-12-2005, 06:35 PM
select count(*) from subscriptionlog where status=1
TrickyD
09-12-2005, 06:52 PM
select count(*) from subscriptionlog where active=1
Kirby, thanks for the reply.
How will running that query allow me to call the value in the header template?
Andreas
09-12-2005, 07:50 PM
Well, just execute it :)
global_start
$subscribers = $db->query_first("SELECT COUNT(*) AS totalactive FROM " . TABLE_PREFIX . "subscriptionlog WHERE active=1");
$subscribers['totalactive'] = vb_number_format($subscribers['totalactive']);
As this adds 1 Query/Page, you might want to cache the Value in Datastore, but that involves more Code - and File Edits.
TrickyD
09-13-2005, 06:23 PM
Well, just execute it :)
global_start
$subscribers = $db->query_first("SELECT COUNT(*) AS totalactive FROM " . TABLE_PREFIX . "subscriptionlog WHERE active=1");
$subscribers['totalactive'] = vb_number_format($subscribers['totalactive']);
As this adds 1 Query/Page, you might want to cache the Value in Datastore, but that involves more Code - and File Edits.
Kirby, thanks again for the help, but I think I'm code stupid.
I attempt to run the query but it gives me the following error
An error occurred while attempting to execute your query. The following information was returned.
error number: 1146
error desc: Table 'trickyd_ncaa.subscriptionlog' doesn't exist
And when I create a new plugin for the global_start.php as you suggested my board gets a fatal error.
Marco van Herwaarden
09-13-2005, 08:20 PM
Then you are probably using a table prefix, and will have to add that in front of tablenames.
TrickyD
09-14-2005, 07:06 AM
Then you are probably using a table prefix, and will have to add that in front of tablenames.
Indeed, my fault there. However when adding the prefix to the query, it returned the following error.
An error occurred while attempting to execute your query. The following information was returned.
error number: 1054
error desc: Unknown column 'active' in 'where clause'
Any thoughts?
Marco van Herwaarden
09-14-2005, 09:07 AM
What is the exact query you are running?
If you are using a table prefix, and are referencing the tablename as identifier for a columnname anywhere the SQL-statement, you should also add an AS clause. Example:
SELECT table1.name, table2.*
FROM " . TABLE_PREFIX . "table1 AS table1
LEFT JOIN " . TABLE_PREFIX . "table2 AS table2 ON (table1.keyid = table2.keyid)
Andreas
09-14-2005, 09:10 AM
My fault - it's status not active
Boofo
09-14-2005, 09:48 AM
My fault - it's status not active
Typo man has struck again! LMAO
Andreas
09-14-2005, 09:49 AM
Nah, that wasn't a typo - just bad (brain) memory.
I don't deal with the subscriptionlog table that often you know.
Boofo
09-14-2005, 09:52 AM
True, but it was still classic. ;)
TrickyD
09-15-2005, 05:46 AM
Thanks again for all the help guys, hopefully this is the last I have to bug you about this particular hack.
So I ran the query with the prefix and updated code as
select count(*) from cmq_subscriptionlog where status=1
And it returned the correct number, 95.
So then I entered the following in the plugin manager for the global_start
$subscribers = $db->query_first("SELECT COUNT(*) AS totalactive FROM " . TABLE_PREFIX . "subscriptionlog WHERE status=1");
$subscribers['totalactive'] = vb_number_format($subscribers['totalactive']);
I went into my header template and entered $subscribers at the top of the template and saved it.
But when I went back to my board to check it, it displalyed ARRAY
What'd I screw up this time :dead:
calorie
09-15-2005, 05:50 AM
Use $subscribers[totalactive] in the template.
TrickyD
09-15-2005, 05:59 AM
Use $subscribers[totalactive] in the template.
Fantastic, works perfect now.
I'd like to throw out one last thank you to all.
TrickyD
06-11-2008, 10:48 PM
I know this thread is from back in 2005, but this mod is still working and has been a huge asset to my forum.
But I've grown and have added other subscriptions.
Here is my question...
How can I modify this code to only count the total active subscribers in a specific subscription?
$subscribers = $db->query_first("SELECT COUNT(*) AS totalactive FROM " . TABLE_PREFIX . "subscriptionlog WHERE status=1");
$subscribers['totalactive'] = vb_number_format($subscribers['totalactive']);
I'm assuming a I need a "subscriptionid=1" in there somewhere?
psylenced
06-12-2008, 04:33 AM
How can I modify this code to only count the total active subscribers in a specific subscription?
$subscribers = $db->query_first("SELECT COUNT(*) AS totalactive FROM " . TABLE_PREFIX . "subscriptionlog WHERE status=1");
$subscribers['totalactive'] = vb_number_format($subscribers['totalactive']);
I'm assuming a I need a "subscriptionid=1" in there somewhere?
That is correct:
$subscribers = $db->query_first("SELECT COUNT(*) AS totalactivesub1 FROM " . TABLE_PREFIX . "subscriptionlog WHERE status=1 AND subscriptionid = 1");
$subscribers['totalactivesub1'] = vb_number_format($subscribers['totalactivesub1']);
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.