Online Player Page?

Status
Not open for further replies.
Newbie Spellweaver
Joined
Feb 15, 2012
Messages
95
Reaction score
14
Prob going to be my last topic with a question:

Does anyone know of a php script that shows Who's currently online? It'd help some people know who's online without the need to actually log in. Plus it's a good tool to keep tabs on people without logging in myself XD
 
I guess this would do.

For the configuration, Save this file as total_user_config.php. Any file name would do as long as it's an php file, but I would prefer to use that file name for easy readable access, and then save it in a folder. any folder name would do, but in the code I named it "configuration" if you desire to make other folder name just change the path on the code so that it'll work.

PHP:
<?php
        $link = @mssql_connect("NAME-PC\SQLEXPRESS", "sa", "PASSWORD") or die ("Cannot connect to database or server.");
        $db = @mssql_select_db('ACCOUNT_DBF') or die ("Account table is missing!");
        $b = 'dbo.ACCOUNT_TBL_DETAIL';
    $mail = '';        
		$query = mssql_query("SELECT * FROM [ACCOUNT_TBL_DETAIL] WHERE isuse = 'J' ");
?>

To implement this on the page, use this;
PHP:
  <?php
require('./configuration/total_user_config.php');
        echo 'Users Online: ' . mssql_num_rows($query); 
?>

Hope that helps.
 
PHP:
   <?php


        $link = @mssql_connect("YOUR HOST", "User", "Password") or die ("Error!");
        $db = @mssql_select_db('ACCOUNT_DBF') or die ("Error!");
        $b = '';
    $mail = '';        
		$query = mssql_query("SELECT * FROM [ACCOUNT_TBL_DETAIL] WHERE isuse = 'J' ");
        echo 'Users Online: ' . mssql_num_rows($query); 
?>

Source : http://forum.ragezone.com/f651/make-users-online-number-617546/

Use the search next time.
 
You are both stupid. Try reading his entire post next time.

He's not looking for a simple number of online users, he's looking for a list of every individual character that is online.

Oh yeah sorry, and mr. not stupid, please post the code that'll help him instead if telling us what we are. k? :thumbup:
 
Oh yeah sorry, and mr. not stupid, please post the code that'll help him instead if telling us what we are. k? :thumbup:

There isn't exactly 1 solution to that problem, it's dependent on his server files. Most that I know of, use the MultiServer column in CHARACTER_TBL to determine if a character is online. Some though, use a separate table for that function. And some, don't have that working at all.
 
1. I'ma She XD
2. Ya'll are silly
3. I'm currently still using Max98's server files. Think that would work? Cause I do see those values change often. Think a script could make a call to that?
 
Lol, sorry about that =P

You should look at this thread: http://forum.ragezone.com/f724/players-online-count-bugs-772109/

Change the query to "SELECT m_szName FROM..."

Then do:
PHP:
while( $data = mssql_fetch_assoc($query) )
{
	echo $data['account']."<br />";
}

That will get you a list of all online chars. You can figure out how to style it after if you want.
 
WOO! Got it =D took a bit of tweeking.

PHP:
<?php


        $link = @mssql_connect("PC Name", "User", "pass") or die ("Error!");
        $mssql = mssql_query("SELECT * FROM [ACCOUNT_DBF].dbo.[ACCOUNT_TBL] WHERE isuse='J'");

echo mssql_num_rows($mssql)." players are online. <br />";
       $query = mssql_query('SELECT m_szName as [CCU] FROM [CHARACTER_01_DBF].[dbo].[CHARACTER_TBL] WHERE [MultiServer] != 0;');
	 
	   while( $data = mssql_fetch_assoc($query) ) 
{ 
    echo $data['CCU']."<br />"; 
}  

?>

all it needs now is som'in that refreshes the page every now and then, or updates the page when someone logs in or out and it'd be PERFECT =D

I'd have an "IF" script for 0 people online but I honestly couldn't figure it out ^_^''

Edit: I added a system that even shows their level =D now if I know how to make "if" strings I'd make a part that even tells what class they are =3


PHP:
<?php


        $link = @mssql_connect("PC Database", "Name", "Pass") or die ("Error!");
        $mssql = mssql_query("SELECT * FROM [ACCOUNT_DBF].dbo.[ACCOUNT_TBL] WHERE isuse='J'");

echo mssql_num_rows($mssql)." players are online. <br /> Player name and Player Level: <br />";
       $query = mssql_query('SELECT m_szName as [CCU] FROM [CHARACTER_01_DBF].[dbo].[CHARACTER_TBL] WHERE [MultiServer] != 0;');
	        $nquery = mssql_query('SELECT m_nLevel as [CCZ] FROM [CHARACTER_01_DBF].[dbo].[CHARACTER_TBL] WHERE [MultiServer] != 0;');
	   while( $data = mssql_fetch_assoc($query) ) 
	   while( $level = mssql_fetch_assoc($nquery) ) 
{ 
    echo $data['CCU'], " ", $level['CCZ']."<br />"; 
}  
?>
 
Last edited:
You need to learn more about PHP and MSSQL Queries

Here, I'll fix up your coding and compare it to yours to see what you did wrong.
PHP:
<?php


        $link = @mssql_connect("PC Database", "Name", "Pass") or die ("Error!");
        $mssql = mssql_query("SELECT * FROM [ACCOUNT_DBF].dbo.[ACCOUNT_TBL] WHERE isuse='J'");

echo mssql_num_rows($mssql)." players are online. <br /> Player name and Player Level: <br />";
       $query = mssql_query('SELECT m_szName, m_nLevel FROM [CHARACTER_01_DBF].[dbo].[CHARACTER_TBL] WHERE [MultiServer] != 0;');
	   while( $data = mssql_fetch_assoc($query) )
{ 
    echo $data['m_szName'], " ", $data['m_nLevel']."<br />"; 
}  
?>

Once you get that down, maybe I'll help with the job part.
 
Oh I see. didn't really need the CCu/CCZ thing, and you combined 2 of my interger calls into 1 line with a , seperator. I was just copying one of the scripts that was posted in here and tried to do my own touches XD I'm still very very greenhorn about php scripts lol.

Edit: After dinking around and moving stuff, finally got a cute lil table made up =D It works rather well ^_^ As seen here:


PHP:
<?php


        $link = @mssql_connect("Pc Database", "Name", "Passy") or die ("Error!");
        $mssql = mssql_query("SELECT * FROM [ACCOUNT_DBF].dbo.[ACCOUNT_TBL] WHERE isuse='J'");
echo '<div align="center"><table width="50%" border="1" bgcolor="#BBBBBB" style="text-align:center;">';
echo '<th>Player Name</th>';
echo '<th>Player Level</th>';
echo '<tr>';
echo mssql_num_rows($mssql)." players are online. <br /><br />";

     $query = mssql_query('SELECT m_szName, m_nLevel FROM [CHARACTER_01_DBF].[dbo].[CHARACTER_TBL] WHERE [MultiServer] != 0;');
{ 
while( $row <= mssql_num_rows($mssql) -1 )
   while( $data = mssql_fetch_assoc($query) )
  //loop through the rows
{
    //loop through elements (ie td's)
	echo '<td>'.$data['m_szName'].'</td>';
	echo '<td>'.$data['m_nLevel'].'</td></tr>';
$row++;
}
echo '</table>'; 
}

?>

Edit2: I can't figure out the "if" lol as many ways I aproched it I came out empty handed. I really need that "If" to tell the page to not attempt to load the table if there's no one online. If not it'll time out the page.
 
Last edited:
Now you're getting it. Now I'll fix up that coding =P

Btw, I honestly don't know how you got a proper looking table doing that. You start a row (<tr>), then end one repeatedly in the while loop, without ever making new ones.

Also, you're using an inefficient and not very reliable way of checking how many people are online. The one I already gave you can be used for both of what you're trying to do at the same time.

PHP:
<?php


$link = @mssql_connect("Pc Database", "Name", "Passy") or die ("Error!");
$query = mssql_query('SELECT m_szName, m_nLevel FROM [CHARACTER_01_DBF].[dbo].[CHARACTER_TBL] WHERE [MultiServer] != 0;');
echo '<div align="center"><table width="50%" border="1" bgcolor="#BBBBBB" style="text-align:center;">';
echo '<th>Player Name</th>';
echo '<th>Player Level</th>';
$online = mssql_num_rows($query);
echo $online." players are online. <br /><br />";

// Here's the proper way to do an If statement
if( $online > 0 )
{
	//loop through the rows
	while( $data = mssql_fetch_assoc($query) )
	{
		//loop through elements (ie td's)
		echo '<tr><td>'.$data['m_szName'].'</td>';
		echo '<td>'.$data['m_nLevel'].'</td></tr>';
	}
}
echo '</table>'; 

?>

Here's a small explanation of the If statement. The part in parenthesis is the key. If whatever is inside that, evaluates to true (like $online being greater than 0) then everything in the braces ( {} ) will be executed. If you don't use braces, then the if statement will only apply to the line immediately after the if statement.
 
Oh geeze lol I was trying to do it like, "if ($row > $mssql)" thing lol Never said I was a coder XD I do try though when I'm serrious about som'in ^_^. I also dono how I got the table to work.. it just kinda does. it's odd XD Thanks again for the cleaning ^_^'' I'll attempt to do the last part (classes) myself. If I'm guessing right, it'd be better if I use a "function"? though I think my brain isn't wired correctly for that LOL
 
You could use a function, but the only purpose of that would be to keep the while loop looking cleaner, cause you can put the function coding in a different location.

Function or not though, you only have to add m_nJob to the query (along with m_szName and m_nLevel), extract that value (which is a number) into a variable, and run a series of If statements to determine what their job is.

Here's an example:
PHP:
$job = $data['m_nJob'];
if( $job == 0 )
	echo "Vagrant";
else if( $job == 1 )
	echo "Mercenary";

The numbers can be found in your DefineJob.h file in your server files.
I used 2 new things there. The second kind of if statement (no braces). That means only the echo after it will be executed.
Another new thing, is the "else if" statement. If the first If statement is false, then it checks any "else if" statements in order until it finds one that is true, or runs out of "else if" statements. If an "else if" statement is true, then it skips any that it hasn't gotten to yet.
 
Now you're getting it. Now I'll fix up that coding =P

Btw, I honestly don't know how you got a proper looking table doing that. You start a row (<tr>), then end one repeatedly in the while loop, without ever making new ones.

Also, you're using an inefficient and not very reliable way of checking how many people are online. The one I already gave you can be used for both of what you're trying to do at the same time.

PHP:
<?php


$link = @mssql_connect("Pc Database", "Name", "Passy") or die ("Error!");
$query = mssql_query('SELECT m_szName, m_nLevel FROM [CHARACTER_01_DBF].[dbo].[CHARACTER_TBL] WHERE [MultiServer] != 0;');
echo '<div align="center"><table width="50%" border="1" bgcolor="#BBBBBB" style="text-align:center;">';
echo '<th>Player Name</th>';
echo '<th>Player Level</th>';
$online = mssql_num_rows($query);
echo $online." players are online. <br /><br />";

// Here's the proper way to do an If statement
if( $online > 0 )
{
    //loop through the rows
    while( $data = mssql_fetch_assoc($query) )
    {
        //loop through elements (ie td's)
        echo '<tr><td>'.$data['m_szName'].'</td>';
        echo '<td>'.$data['m_nLevel'].'</td></tr>';
    }
}
echo '</table>'; 

?>
Here's a small explanation of the If statement. The part in parenthesis is the key. If whatever is inside that, evaluates to true (like $online being greater than 0) then everything in the braces ( {} ) will be executed. If you don't use braces, then the if statement will only apply to the line immediately after the if statement.

i try this but it's blank?

 
Kinda figured that what an elseif woulda done. Rock on =D Thanks for the assistance XD Even though My way was pretty sloppy lol Now that I think about it, it's much like making NPCs from Ragnarok online. Should aproch it like that.

Oh one last thing, as I for sure would never figure this one out: Is there a way to "softly" refresh the table on a timer? I've seen it done before in another game using a php script but I don't have it's file anymore (I think)
 
Status
Not open for further replies.
Back