• 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!

[Gesior AAC] [0.3] Census

Koci1994

Banned User
Joined
Dec 27, 2008
Messages
807
Reaction score
1
Hello
I would like to show you the script which counting vocations and sex Players

Script:
Code:
  <?PHP
$voc=array (1 => 'Sorcerer', 2 => 'Druid', 3 => 'Paladin', 4 => 'Knight');  
 
$genderCensus = $SQL->query('SELECT `sex` AS `key`, COUNT(`id`) AS `value` FROM `players` GROUP BY `sex`')->fetchAll(PDO::FETCH_KEY_PAIR);
$vocationCensus = $SQL->query('SELECT `vocation` AS `key`, COUNT(`id`) AS `value` FROM `players` GROUP BY `vocation`')->fetchAll(PDO::FETCH_KEY_PAIR);

// prepares calculation variables
$genderCount = array_sum($genderCensus) / 100;
$vocationCount = array_sum($vocationCensus) / 100;



$main_content .='<h1>Genders</h1>';
$main_content .='<table align="center" width="400px" border="1px">';


$gender = array('male'=> (int) $genderCensus[0] . ' (' . @intval($genderCensus[0] / $genderCount) . '%)','female' => (int) $genderCensus[1] . ' (' . @intval($genderCensus[1] / $genderCount) . '%)');
$main_content .= '<tr><td width="20%">Males: </td><td>'.$gender['female'].'</td></tr>';
$main_content .= '<tr><td width="20%">Females: </td><td>'.$gender['male'].'</td></tr>';

$main_content .='</table>';


$vocations = array();


foreach($voc as $id => $name)
{
    $vocations[$name] = (int) $vocationCensus[$id] . ' (' . @intval($vocationCensus[$id] / $vocationCount) . '%)';


}
$main_content .='<h1>Vocations</h1>';
$main_content .='<table align="center" width="400px" border="1px">';
for($i=1; $i<=count($voc); $i++) {
    $main_content .='<tr><td width="20%">'.$voc[$i].'</td><td>'.$vocations[$voc[$i]].'</td></tr>';
}
$main_content .='</table>';


?>
Screen:
2vdmqns.jpg
 
Last edited by a moderator:
Haha, Koci! The biggest noob of polish board is releasing something! Congratulations for you and thanks for releasing. :O
 
Haha, Koci! The biggest noob of polish board is releasing something! Congratulations for you and thanks for releasing. :O

If he is the biggest noob of polish board, then the average polish users in this forum has to be quite smart? :confused:
 
Updated Script :
Code:
 <?PHP
$voc=array (1 => 'Sorcerer', 2 => 'Druid', 3 => 'Paladin', 4 => 'Knight');  
 
$genderCensus = $SQL->query('SELECT `sex` AS `key`, COUNT(`id`) AS `value` FROM `players` GROUP BY `sex`')->fetchAll(PDO::FETCH_KEY_PAIR);
$vocationCensus = $SQL->query('SELECT `vocation` AS `key`, COUNT(`id`) AS `value` FROM `players` GROUP BY `vocation`')->fetchAll(PDO::FETCH_KEY_PAIR);

// prepares calculation variables
$genderCount = array_sum($genderCensus) / 100;
$vocationCount = array_sum($vocationCensus) / 100;



$main_content .='<h1>Genders</h1>';
$main_content .='<table align="center" width="400px" border="1px">';


$gender = array('male'=> (int) $genderCensus[0] . ' (' . @intval($genderCensus[0] / $genderCount) . '%)','female' => (int) $genderCensus[1] . ' (' . @intval($genderCensus[1] / $genderCount) . '%)');
$main_content .= '<tr><td width="20%">Males: </td><td>'.$gender['female'].'</td></tr>';
$main_content .= '<tr><td width="20%">Females: </td><td>'.$gender['male'].'</td></tr>';

$main_content .='</table>';


$vocations = array();


foreach($voc as $id => $name)
{
    $vocations[$name] = (int) $vocationCensus[$id] . ' (' . @intval($vocationCensus[$id] / $vocationCount) . '%)';


}
$main_content .='<h1>Vocations</h1>';
$main_content .='<table align="center" width="400px" border="1px">';
for($i=1; $i<=count($voc); $i++) {
    $main_content .='<tr><td width="20%">'.$voc[$i].'</td><td>'.$vocations[$voc[$i]].'</td></tr>';
}
$main_content .='</table>';


?>
 
If he is the biggest noob of polish board, then the average polish users in this forum has to be quite smart? :confused:

As Paxton said, they are idiots. I just can't belive it Koci did something :O
 
it's really safe, but not running too fast, I think that koci1994 hasn't got much more experiences with php :)
I tried other sql queries and even load all sex in php and count it in php, but generate time is still ~0.3 sec (300 ms) with 50.000 characters in database.
Players online list generate in 0.018 sec, highscores in ~0.8 sec (I use cache for highscores [load data from database if last refresh time > 10 sec] - no problem).
@Samme
Why should we copy all from Elf's ots ? :D
( WypasOTS - Census
//
WypasOTS - Census )
It's coololol. Maybe ask Elf about script.
He will send me guilds script with guild image upload fixed :)
------------------------------
On my ots ~5% players read news/use acc. maker after create priv. account. Scripts for players are useless (search character and highscores are most popular). Better make scripts to detect boters and help new players (show map/vocation info on site).
 
Back
Top