• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

[PHP] Get highest player from MYSQL Database

atyll

Member
Joined
Dec 30, 2008
Messages
380
Reaction score
16
Hello Guys

I have managed to get total number of players:
Code:
<?php
								$SQL = AAC::$SQL;
								$SQL->myQuery('SELECT players.sex, COUNT(players.id) as number FROM `players` GROUP BY players.sex');
                $total = 0;
                while ($a = $SQL->fetch_array()) {
                    $genders[$a['sex']] = $a['number'];
                    $total += $a['number'];
                }
				$gender_names = array(0 => 'Female',1 => 'Male');
				echo "$total";
               
								
								?>

However, I can't manage to get player with highest level and skill (get Highest Level and Name).
Anybody would be able to help?

Regards
Jakub
 
SQL:
SELECT `name`, `level` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1
assuming you don't want gender involvement
 
Doesn't work.
I use this code and shows just 0.

Code:
<?php
$SQL = AAC::$SQL;
$SQL->myQuery('SELECT `name`, `level` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1');
                $total = 0;
                while ($a = $SQL->fetch_array()) {
                    $level[$a['level']] = $a['number'];
                    $total += $a['number'];
                }
				echo "$total";
               ?>
 
PHP:
$SQL->myQuery('SELECT `name`, `level` FROM `players` ORDER BY `level` DESC, `experience` DESC LIMIT 1')->fetch();

echo 'Rank 1: '.$SQL['name'].' Level: '.$SQL['level'];

this runs it and echo its out i dont se any problem with it from here XD
didnt do it in any editor so cant se if its wrong
 
Try

PHP:
$query = $SQL->query("SELECT * FROM `players` WHERE `group_id` < 3 ORDER BY `experience` DESC")->fetch();
 
PHP:
$query = $SQL->myQuery("SELECT * FROM `players` WHERE `group_id` < 3 ORDER BY `experience` DESC")->fetch();

echo 'Rank 1: '.$query['name'].' Level: '.$query['level'];
 
And once again, sorry to be pain, guys

Code:
Fatal error: Call to a member function fetch() on a non-object in C:\xamppp\htdocs\test\menu2.html on line 283
 
PHP:
$query = $SQL->myQuery("SELECT * FROM `players` ORDER BY `experience` DESC")->fetch();
        echo 'Rank 1: '.$query['name'].' Level: '.$query['level'];

i tested it and it worked. i think the gruop_id is something you dont have
 
PHP:
$query = $SQL->myQuery("SELECT * FROM `players` ORDER BY `experience` DESC")->fetch();
        echo 'Rank 1: '.$query['name'].' Level: '.$query['level'];

i tested it and it worked. i think the gruop_id is something you dont have

Why the fuck would you include fetch() everytime knowing the error?
 
Your code didn't work for me, sorted it out myself.

HOWEVER, I don't how to get Skills and name of the player with highest skill now ;)
This is the code I use to get level:

Code:
<?php
							
$data = mysql_query("SELECT * FROM `players` ORDER BY `experience` DESC") 
or die(mysql_error()); 

$info = mysql_fetch_array( $data ); 
Print "<b>Top:</b> ".$info['name'] . " "; 
Print "<br /><b>Level:</b> ".$info['level'] . " "; 
		
?>

How can I use this code, to pick from player_skills, order by skill 5 (shielding) and get highest value?
Thanks in advance for help, guys!
 
Last edited:
Your code didn't work for me, sorted it out myself.

HOWEVER, I don't how to get Skills and name of the player with highest skill now ;)
This is the code I use to get level:

Code:
<?php
							
$data = mysql_query("SELECT * FROM `players` ORDER BY `experience` DESC") 
or die(mysql_error()); 

$info = mysql_fetch_array( $data ); 
Print "<b>Top:</b> ".$info['name'] . " "; 
Print "<br /><b>Level:</b> ".$info['level'] . " "; 
		
?>

How can I use this code, to pick from player_skills, order by skill 5 (shielding) and get highest value?
Thanks in advance for help, guys!

Code:
<?php
							
$data = mysql_query("SELECT * FROM player_skills WHERE skillid = 5 ORDER BY value DESC") 
or die(mysql_error()); 


$info = mysql_fetch_array( $data ); 

$data2 = mysql_query("SELECT name FROM players WHERE id = ".$info['player_id']."") 
or die(mysql_error()); 

$info2 = mysql_fetch_array( $data2 ); 

Print "<b>Top:</b> ".$info2['name'] . " "; 
Print "<br /><b>Level:</b> ".$info['value'] . " "; 
		
?>
mby something like this, there's probably some faster way but i don't know how to multiple tables etc because im a noob;P<3
 
@up


Now I get
Code:
Top: ".$info2['name']."
"; echo "Level: ".$info['value']; ?>

:D

- - - Updated - - -

OMG I found the error, very silly...

I had <? php instead of <?php :D

Thanks a lot for help guys!
You can check what I did on http://danera.no-ip.org

God bless you all!
 
Last edited:
Back
Top