Registered Counter [Private Server]

11/24/2013 21:46 darkorbitplayer1118#1
Hello epvpers! Today I present to you the Registered Counter v.1. All the information is presented below. :rolleyes:


Registered Counter Code:
PHP Code:
<?php 
// [MySQL] Config
$host "localhost";
$username "root";
$password "";       // Leave blank if no password.
$database "";       // Your Private Server Database.
$table "users";

// Connect to mysql.
mysql_connect("$host","$username","$password") or die (mysql_error());
mysql_select_db("$database") or die (mysql_error());

// Database fuctions.
$usercount mysql_query("SELECT * FROM $table") or die (mysql_error());
$count mysql_num_rows($usercount);

echo 
"Registered:".$count;

// Created by darkorbitplayer1118
?>
* Make sure to type your database name and your password (leave blank if you have no password).

--------------------------------------------------
Want it in a php file instead?
Download link below.

DownloadVirustotal 
[Only registered and activated users can see links. Click Here To Register...][Only registered and activated users can see links. Click Here To Register...] 
--------------------------------------------------
Instructions:

File Location:
[Only registered and activated users can see links. Click Here To Register...]

Code Location (to place new code):
[Only registered and activated users can see links. Click Here To Register...]

New Code (same place were old code was at):
[Only registered and activated users can see links. Click Here To Register...]

Registration Page:
[Only registered and activated users can see links. Click Here To Register...]
--------------------------------------------------
There you go works 100% :D
Have Fun! :handsdown:
11/24/2013 22:15 Requi#2
Doesn't ICON8 already have it?
Sky Universe as example.
11/24/2013 22:21 darkorbitplayer1118#3
Quote:
Originally Posted by Requi View Post
Doesn't ICON8 already have it?
[Only registered and activated users can see links. Click Here To Register...] as example.
Hmm i guess this code will be used for Azure and Aroura I guess. :P
11/24/2013 22:21 UND3RW0RLD#4
Proper version:

Put this in your backend:
PHP Code:
function usercount()
{
    
$usercount mysql_query("SELECT COUNT(*) FROM users") or die(mysql_error());

    echo 
"Registered:".mysql_result($usercount,0); 

and now you can use this function on various places of your website.

+ much faster
+ execution time does not depend on how big the db is
+ reusable
11/24/2013 22:25 darkorbitplayer1118#5
Quote:
Originally Posted by ǝnd1ǝss-ɯonǝʎ View Post
Proper version:

Put this in your backend:
PHP Code:
function usercount()
{
    
$usercount mysql_query("SELECT COUNT(*) FROM users") or die(mysql_error());

    echo 
"Registered:".$usercount

and now you can use this function on various places of your website.

+ much faster
+ execution time does not depend on how big the db is
+ reusable
Thanks for the advice but all I need to do is put an include function and put the mysql configuration in a separate file to fix the problem to be usable all over the website. Thank you anyways.

EDIT: Tested your code and it seems to not work for me. Does it need the Mysql config?
11/25/2013 10:43 UND3RW0RLD#6
To get it work you need a clearly structurated webkit.

$root/backend/secrets.php <-- Put the SQL-connection here
$root/backend/globalfunc.php <-- include "secrets" here and put the new function in here

$root/index.php <-- include globalfunc.php here and just execute the new function with
"usercount()"
11/25/2013 15:50 Luffa#7
Quote:
Originally Posted by ǝnd1ǝss-ɯonǝʎ View Post
Proper version:

Put this in your backend:
PHP Code:
function usercount()
{
    
$usercount mysql_query("SELECT COUNT(*) FROM users") or die(mysql_error());

    echo 
"Registered:".mysql_result($usercount,0); 

and now you can use this function on various places of your website.

+ much faster
+ execution time does not depend on how big the db is
+ reusable
It is a lot faster to use functions.
And if you even build-ed it into one of the existing class files, then you would save space.
And reusable when you have required it in an init file, so you would just need to use:
PHP Code:
$userb->playerCount(); 
Or if it is in same class script:
PHP Code:
self::playerCount(); 
Here is my examples of what you could do.
And it is also reusable, and uses pdo.

Example from my server-config
PHP Code:
## SQL Server Data
/*
$Config['MySQL'] = [
    'host' => 'localhost',
    'user' => 'root',
    'pass' => '',
    'dbname' => 'darkorbit'
];
*/
$Config = new stdClass();
$Config->MySQL = new stdClass();
$Config->MySQL->host "localhost";
$Config->MySQL->user "root";
$Config->MySQL->pass "";
$Config->MySQL->dbname "darkorbit"

define"DB_DSN""mysql:host=".$Config->MySQL->host.";dbname=".$Config->MySQL->dbname.""); //this constant will be use as our connectionstring/dsn
define"DB_USERNAME"$Config->MySQL->user ); //username of the database
define"DB_PASSWORD"$Config->MySQL->pass ); //password of the database 
Example class code returning the total number of the table: Class.Userbase.php
PHP Code:
class Userbase{
    private 
$con;
    
    public function 
__construct() {
        
$this->con = new PDO(DB_DSNDB_USERNAMEDB_PASSWORD);
        
$this->con->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
        
    }

 public function 
playerCount(){
         
$query $this->con->prepare("SELECT COUNT(*) FROM tablename");
            if (
$query->execute()) {
                    
$count $query->rowCount();
               return 
$count
            
}
    }


This should actually work with azure->boxxy/madatek version.

And remember to edit the init.php
PHP Code:
require_once 'Class.Userbase.php';
$userb= new Userbase(); 
Then this on the front page should actually be enough.
PHP Code:
print_r($userb->playerCount()); 
I love PDO *-*

Best Regards RQ