MyBB Community Forums

Full Version: PHP MySQL Function - Not MyBB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey guys,

I'm having trouble doing a basic count function.

The PHP:
function get_current_users($current_users) 
{
	global $db;
	$current_users = $db->EscapeString($current_users);
	$total_current_users = $db->QueryFetchArray("SELECT COUNT(*) FROM users AS total_current_users");
	return $total_current_users['total_current_users'];
}

The MySQL query works but I have no clue what to use to ouput the result, i've tried so many options like:

<?$current_users?>
<?$total_current_users?>
<?['$total_current_users']?>
<?=data['$total_current_users']?>

But they all ouput nothing, maybe one of you can spot something I'm doing wrong
echo get_current_users(null);
Have you tried just dumping the $total_current_users array?

echo '<pre>';
var_dump($total_current_users);
echo '</pre>';
(2012-11-14, 10:15 PM)Omar G. Wrote: [ -> ]
echo get_current_users(null);

Ok I added that in:

<h2>Account Stats - Total Users: <?echo get_current_users(null); ?></h2>

It displays nothing still Sad
<?php
echo $current_users;
?>
Just a guess - you didn't say you tried this in your first post
Damn my slow internet made me wait five mins before it posted this.
(2012-11-14, 10:16 PM)euantor Wrote: [ -> ]Have you tried just dumping the $total_current_users array?

echo '<pre>';
var_dump($total_current_users);
echo '</pre>';

I've use that in there as:

<h2>Account Stats - Total Users: <?echo '<pre>';
var_dump($total_current_users);
echo '</pre>'; ?></h2>

And it's display now as:

Account Stats - Total Users:
NULL

At least there's something displaying now, but how come it's null?

When I run the query in phpmyadmin it shows:

COUNT(*)
3243
(2012-11-14, 10:17 PM)Hostpro Wrote: [ -> ][quote='Omar G.' pid='938045' dateline='1352931342']
<?echo get_current_users(null); ?>


try modifying this to read:


<?php echo get_current_users(null); ?>

Short tags aren't supported by all servers, and in all cases they require a space
(2012-11-14, 10:19 PM)Ben Cousins Wrote: [ -> ]
(2012-11-14, 10:17 PM)Hostpro Wrote: [ -> ][quote='Omar G.' pid='938045' dateline='1352931342']
<?echo get_current_users(null); ?>


try modifying this to read:


<?php echo get_current_users(null); ?>

Short tags aren't supported by all servers, and in all cases they require a space

Displays nothing again Sad

<h2>Account Stats - Total Users: <?php echo get_current_users(null); ?></h2>
Is this in a template in the MyBB System?
(2012-11-14, 10:23 PM)Ben Cousins Wrote: [ -> ]Is this in a template in the MyBB System?

Nope, it's for my traffic exchange, I'm trying to make my own widget from scratch to show a percentage bar.

I was going to select the total users I have using the query above^ Then I know the php functions to find a percentage of 2 values which I can use in my progress bar to show percentage towards the goal users.

I'm just having trouble displaying a result for this Sad
Pages: 1 2