Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Help] Please, help with the users online

Joined
Feb 24, 2014
Messages
20
Reaction score
0
Hi everyone, i have a problem whit the users online, when i tried to show the users online in the notice.php the users is incremented automatically in "concurrentuser" for example, in my server are 4 users in the notice.php are 4-6-8-10-12-14-16-18 ......... i tried to solve this, but i can´t maybe some one helpme please.
 
Joined
Feb 24, 2014
Messages
20
Reaction score
0
Hi, i'm using this php

<?php echo $total = mysql_num_rows(mysql_query("SELECT * FROM concurrentuser")); //echo $total; ?>


Maybe u can help me with this problem, thanks :)
 
Junior Spellweaver
Joined
Oct 9, 2009
Messages
187
Reaction score
29
SELECT SUM(`UserCount`) FROM
(
SELECT
`UserCount`
FROM
`concurrentuser`
WHERE `Time` =
( SELECT
MAX(`Time`)
FROM
`concurrentuser`
WHERE `ServerPort` = '8360')
UNION
SELECT
`UserCount`
FROM
`concurrentuser`
WHERE `Time` =
( SELECT
MAX(`Time`)
FROM
`concurrentuser`
WHERE `ServerPort` = '8361')
) cnt

i already sum it so just replace the php query SELECT * FROM concurrentuser inside

concurrentuser is time based, its logs the online users per value, so even there is no player in the servers, its will just add rows in concurrentuser per minute.

if you have more than 2 servers, just add another

UNION SELECT
`UserCount`
FROM
`concurrentuser`
WHERE `Time` =
( SELECT
MAX(`Time`)
FROM
`concurrentuser`
WHERE `ServerPort` = '836x')
after
WHERE `ServerPort` = '8361')
in the current query
 
Junior Spellweaver
Joined
Oct 9, 2009
Messages
187
Reaction score
29
mysql_select_db('gunbound');
$query = "SELECT SUM(`UserCount`) ol FROM (SELECT `UserCount` FROM `concurrentuser` WHERE `Time` = ( SELECT MAX(`Time`) FROM `concurrentuser` WHERE `ServerPort`='8360')) cnt GROUP BY `UserCount`;";
$result = mysql_query($query, $conn );

if (!$result) exit("The query did not succeded");
else {
while ($row = mysql_fetch_array($result)) {
echo "Online: "+ $row['ol'];
}
}

you dont need to count the rows, just display the row value returned.
 
Junior Spellweaver
Joined
Oct 9, 2009
Messages
187
Reaction score
29
<?php

$servername = "localhost";
$username = "root";
$password = "";
$conn = mysql_connect($servername, $username, $password);

// Check connection

if(! $conn ) {
die('Could not connect: ' . mysql_error());
}



mysql_select_db('gunbound');
$query = "SELECT SUM(`UserCount`) ol FROM (SELECT `UserCount` FROM `concurrentuser` WHERE `Time` = ( SELECT MAX(`Time`) FROM `concurrentuser` WHERE `ServerPort`='8360')) cnt GROUP BY `UserCount`;";
$result = mysql_query($query, $conn );

if (!$result) exit("The query did not succeded");
else {
while ($row = mysql_fetch_array($result)) {
echo "Online: ". $row['ol'];
}
}
?>
use this one
 
Joined
Feb 24, 2014
Messages
20
Reaction score
0
Hi bro, I have a problem, when I tried to join my other server (8361)I have a problem, how I can join the server 8360 and 8361? I'm use the sentence UNION, I'm using your PHP :)

<?php

$servername = "XXX.XXX.XXX.XXX";
$username = "root";
$password = "XXXXXXXX";
$conn = mysql_connect($servername, $username, $password);

// Check connection

if(! $conn ) {
die('Could not connect: ' . mysql_error());
}



mysql_select_db('gunbound');
$query = "SELECT SUM(`UserCount`) ol FROM (SELECT `UserCount` FROM `concurrentuser` WHERE `Time` = ( SELECT MAX(`Time`) FROM `concurrentuser` WHERE `ServerPort`='8360')) cnt GROUP BY `UserCount`;";
UNION
SELECT `UserCount` FROM `concurrentuser` WHERE `Time` = ( SELECT MAX(`Time`) FROM `concurrentuser` WHERE `ServerPort`='8361') cnt GROUP BY `UserCount`;
$result = mysql_query($query, $conn );

if (!$result) exit("The query did not succeded");
else {
while ($row = mysql_fetch_array($result)) {
echo "Online: ". $row['ol'];
}
}
?>
 
Back
Top