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:
Screen:
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>';
?>
Last edited by a moderator: