Tutorials
Total member count
-
Total member count
Posted on September 4, 2003
Written by
Sasha (view more by Sasha)
Comments (0)
Filed under Scripts: PHPFanBase, Tutorials
With this little script, you’ll be able to display a "Total Member Count" of all your fanlistings together, as seen on the first page of my collective.
If you’re already using the Total Individual Member Count Tutorial, this’ll be very easy to implement, as you can use the same arrays.php file for it.
You need to be using phpFanbase v1 or v2.x, and your fanlistings need to be hosted on the same server as the site you want to display this on, with all the tables for those fanlistings in the same database.
Open up your text editor, and create a new, blank document. Save it as arrays.php, and paste the following code into it:
<?php
$fl_total = array('table1', 'table2', 'table3');
?>
Replace the table1, table2 and table3 with the names of the tables as you specified it in each FL’s config.php file. If you want to include more than 3 fanlistings, just add " ‘tablename’, " for each. Remember to put a comma inbetween every tablename you add, and to NOT put a comma behind the last one.
Save the file, and upload it to the same directory as the page you want to display the count on.
Now open up that page (the one you want to display the count on) in your text editor. Please note that this page MUST have a .php extension in order for this to work!
Add the following code where you want the count to show up:
<?php
$database = 'databasename'; //the name of the database containing all your FLs
$user = 'username'; // the username that has access to the above database
$pass = 'password'; // your MySQL password
$host = 'localhost';
$link = @mysql_connect($host, $user, $pass) or die('Unable to select database');
@mysql_select_db($database, $link) or die('Unable to select database');
require 'arrays.php';
sort($fl_total);
$totalnum = 0;
foreach($fl_total as $fl) {
$query = mysql_fetch_assoc(mysql_query('SELECT COUNT(id) AS num FROM ' . $fl . " WHERE apr = 'y'"));
$totalnum += $query['num'];
}
$totalnum = number_format($totalnum);
echo 'Total mumber of fans listed: <strong>' . $totalnum . '</strong>';
?>
And that’s all!
Save the files, upload them, and it should work like a charm.
Comments
Comments are closed for this entry.