/    Sign up×
Community /Pin to ProfileBookmark

Forum member count

I am trying to get a page to display a total number of members on my forum so have done the following:

created a page containing:

[CODE] <?php
$db_host = ‘localhost’;
$db_user = ‘xx’;
$db_password = ‘xx’;
$db_name = ‘adejones_phpb1’;

mysql_connect($db_host,$db_user,$db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());

$result = mysql_query(“SELECT num_users as count FROM phpbb_config”);
echo ‘Total members: ‘.$result[‘count’].'<br>’;
?>[/CODE]

All this does it display “Total members:” with no value afterwards, what am I doing wrong here?

Thanks, Adey

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@WyCnetApr 21.2012 — The following snippet can get you closer to your goal:

$result = mysql_query("SELECT num_users as count FROM phpbb_config");
if(mysql_num_rows($result)==0)
echo 'There are no members. '.'&lt;br&gt;';
else{
$data=mysql_fetch_assoc($result);
echo 'Total members: '.$data['count'].'&lt;br&gt;';
}

Copy linkTweet thisAlerts:
@djadejonesauthorApr 21.2012 — Hi WyCnet

That code gave me the following:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/adejones/public_html/membercount.php on line 11

There are no members.

I did get a bit closer with the following though:

[CODE]$query = "SELECT config_value FROM phpbb_config WHERE config_name='num_users'";
$result = mysql_query($query);
$array=mysql_fetch_assoc($result);
print_r($array);[/CODE]


This gives me:

Array ( [config_value] => 974 )

Now I just need to get rid of the array config value bit and have just the number.
×

Success!

Help @djadejones spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...