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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...