Registered Count on Header

Status
Not open for further replies.
Joined
Jun 27, 2009
Messages
1,645
Reaction score
287
Ok, i started to learn PHP and MySQL i created a little script for people that don't have the Registered Count on the the Header Here we go

First open inc/class.core.php

find

PHP:
public static function UsersOnline()
	{
		$online = mysql_fetch_array(mysql_query("SELECT * FROM server_status"));
		return intval($online['users_online']);
	}

Under it add

PHP:
 public static function UsersRegistered()
	{
		$register = mysql_query("SELECT * FROM users");  
                return intval ($users = mysql_num_rows($register));
	}

Save it and Done with that

Now Open header.php

find

PHP:
<div class="OnlineCount"><?php echo $core->UsersOnline(); ?> <?php echo $lang['users_online']; ?></div>

Under it add this

PHP:
<div class="RegisterCount"><?php echo $core->UsersRegistered(); ?> <?php echo $lang['registered']; ?></div>

Also for got Open header.php again

find

PHP:
function RefreshUserCount()
{
var html = $.ajax({
url: "online.php",
async: false
}).responseText;
$('.OnlineCount').fadeOut(200, function () {
$('.OnlineCount').css("display", "none")
$('.OnlineCount').html(html + ' <?php echo $lang['users_online']; ?>')
$('.OnlineCount').fadeIn(200)
});
setTimeout("RefreshUserCount()",120000);
}

Under it add

PHP:
function UsersRegistered()
{
var html = $.ajax({
url: "registered.php",
async: false
}).responseText;
$('.RegisterCount').fadeOut(200, function () {
$('.RegisterCount').css("display", "none")
$('.RegisterCount').html(html + ' <?php echo $lang['users_online']; ?>')
$('.RegisterCount').fadeIn(200)
});
setTimeout("UsersRegistered()",120000);
}

Now open lang/en.php

find

PHP:
'users_online' => 'Users Online'

under it add

PHP:
'registered' => 'Users Registered'

Then after that all done Create and File called registered.php and place this in it

PHP:
<?php
define('USERNAME_REQUIRED', FALSE);
define('ACCOUNT_REQUIRED', FALSE);
include('global.php');
echo $core->UsersRegistered();
?>

Then your Done!!!

Screenie:

Glee - Registered Count on Header - RaGEZONE Forums


UPDATED

For the Registered to show on index page open index.php

fine

PHP:
<?php echo $core->UsersOnline(); ?> <?php echo $lang['users_online']; ?>

beside it add

PHP:
<br /> <?php echo $core->UsersRegistered(); ?> <?php echo $lang['registered']; ?>

Make sure you have the <br />
 
Last edited:
Good job. Pretty much the same way i did it.... U even used the lang file...
 
Why did you bother to make it use more resources then it needed to. You could of easily done something like this as your functions which a) use less resources and b) take less time to execute (seeing as PHP is an interpreted language).

NOTE: Not tested, but you should get the idea.

Code:
// Code inside total registered.

return mysql_query("SELECT DISTINCT COUNT(*) FROM users;");

// Code inside total online.

return mysql_query("SELECT DISTINCT COUNT(*) FROM users AS u WHERE u.online = '1';");

Hopefully you'll learn from this project so the next one is better. Have fun.
 
Last edited:
Why did you bother to make it use more resources then it needed to. You could of easily done something like this as your functions which a) use less resources and b) take less time to execute (seeing as PHP is an interpreted language).

NOTE: Not tested, but you should get the idea.

Code:
// Code inside total registered.

return mysql_query("SELECT DISTINCT COUNT(*) FROM users;");

// Code inside total online.

return mysql_query("SELECT DISTINCT COUNT(*) FROM users AS u WHERE u.online = '1';");

Hopefully you'll learn from this project so the next one is better. Have fun.

Putting this on the header.php screw's up the CMS
 
NOTE: Not tested, but you should get the idea.

Code:
// Code inside total registered.

return mysql_query("SELECT DISTINCT COUNT(*) FROM users;");

// Code inside total online.

return mysql_query("SELECT DISTINCT COUNT(*) FROM users AS u WHERE u.online = '1';");

Hopefully you'll learn from this project so the next one is better. Have fun.

His code is fine. Yours is making MySQL do even more work doing that. Why do you over-engineer things that shouldn't be ?

Even though this is simple it's a start and a good effort. Congrats!
 
His code is fine. Yours is making MySQL do even more work doing that. Why do you over-engineer things that shouldn't be ?

LOL and you're trying to tell me you have this amazing "mystery" work on your computer when you say something as stupid as that. Go back to w3schools rock star :wink:.
 
It's a ok release, very simple, but good job! Sad I don't use PhoenixPHP anymore.
 
LOL and you're trying to tell me you have this amazing "mystery" work on your computer when you say something as stupid as that. Go back to w3schools rock star :wink:.

This guy has just released something so basic and he's new to coding. But it's better than anything you've ever contributed. And why would I need to do that ? Prove my work isn't on my computer :)
 
Status
Not open for further replies.
Back