Jump to content
  • 0

PHP - Script Players Online for WebSite


Question

10 answers to this question

Recommended Posts

  • 0
Posted

-.- ..... all script?

 

This is what your code should look like:

<?php
$mysql_connect = ( "ip_of_server", "mysql_user", "mysql_password" );
$mysql_select = mysql_select_db( "name_of_l2j_db" );
$player_query = mysql_query( "SELECT char_name FROM characters WHERE online = 1" );
$player_count = mysql_num_rows( $player_query );
echo $player_count;
$mysql_connect.close();
?>

  • 0
Posted

<?

$host = "127.0.0.1";
$username = "root";
$password = "root";
$db_name = "l2jdb";

function connect_db() {
mysql_connect("$host", "$username", "$password")or die("Can't connect to the database."); 
}

function select_db() {
mysql_select_db("$db_name")or die("Can't select the database.");
}

//query variables
$field = "char_name";
$table = "characters";
$value = "1";
$rule = "online";

connect_db();
select_db();

$query = mysql_real_escape_string(mysql_query("SELECT $field FROM $table WHERE $rule = $value"));
$count = mysql_num_rows($query);
echo "Players online: "$count".";

?>

 

Haven't tested it, as it doesn't save the result to a file and just display the file I advise not using it on a server that's going to have a lot of traffic going to the website. But as you've asked for this, i doubt you plan on that anyway.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..