Tutorials

Total individual member count

With this little script, you’ll be able to display a "Total Member Count" for each of your fanlistings, all together on one page, as seen on the Member Count Page of my collective.

If you’re already using the Total 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. :)

Note: You can skip this step if you are using Total Member Count (see link above), since you’ll already have created this file.

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 individual counts 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'; // your MySQL host - usually localhost, but if this doesn't work, ask your host

$link = @mysql_connect('localhost', $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); ?>

<table border="0" cellpadding="10" cellspacing="5">
	<tr>
		<td colspan="3"><strong><?php echo count($fl_total); ?> Fanlistings hosted here</strong></td>
	</tr>

<?php
foreach($fl_total as $fl) {
	$query = mysql_fetch_assoc(mysql_query('SELECT COUNT(id) AS num_approved FROM ' . $fl . " WHERE apr = 'y'", $link));
	$query2 = mysql_fetch_assoc(mysql_query('SELECT COUNT(id) AS num_pending FROM ' . $fl . " WHERE apr != 'y'", $link)); ?>
	<tr>
		<td><p><?php echo $fl; ?></p></td>
		<td><p><strong><?php echo $query['num_approved']; ?></strong> Fans listed</p></td>
		<td><p><strong><?php echo $query2['num_pending']; ?></strong> Fans pending</p></td>
	</tr><?php
}
?>
</table>

And that’s all! :) Save the files, upload them, and it should work like a charm.

Note: if you’d like to display the FL’s names instead of the table names, take a look here.

Comments

Error Comments are closed for this entry.