Fixed a rounding bug

+General statistics and server info tribe percentages are now shown
correctly
This commit is contained in:
Pietro Fallanca
2018-04-13 19:20:19 +02:00
parent 1b3f4eadd1
commit 86070d1691
4 changed files with 14 additions and 56 deletions
+4 -4
View File
@@ -13,7 +13,7 @@ $tribe1 = mysqli_query($GLOBALS["link"], "SELECT SQL_CACHE * FROM ".TB_PREFIX."u
$tribe2 = mysqli_query($GLOBALS["link"], "SELECT SQL_CACHE * FROM ".TB_PREFIX."users WHERE tribe = 2");
$tribe3 = mysqli_query($GLOBALS["link"], "SELECT SQL_CACHE * FROM ".TB_PREFIX."users WHERE tribe = 3");
$tribes = Array(mysqli_num_rows($tribe1),mysqli_num_rows($tribe2),mysqli_num_rows($tribe3));
$users = mysqli_num_rows(mysqli_query($GLOBALS["link"], "SELECT SQL_CACHE * FROM ".TB_PREFIX."users")) - 1;
$users = mysqli_num_rows(mysqli_query($GLOBALS["link"], "SELECT SQL_CACHE * FROM ".TB_PREFIX."users WHERE tribe > 0 AND tribe < 4"));
?>
<br /><br />
@@ -73,17 +73,17 @@ $users = mysqli_num_rows(mysqli_query($GLOBALS["link"], "SELECT SQL_CACHE * FROM
<tr>
<td>Romans</td>
<td><?php echo $tribes[0]; ?></td>
<td><?php $percents = 100*($tribes[0] / $users); echo $percents = intval ($percents); echo "%"; ?></td>
<td><?php echo ($users > 0) ? ($percents[0] = round(100 * ($tribes[0] / $users), 2))."%" : "---"; ?></td>
</tr>
<tr>
<td>Teutons</td>
<td><?php echo $tribes[1]; ?></td>
<td><?php $percents = 100*($tribes[1] / $users); echo $percents = intval ($percents); echo "%";?></td>
<td><?php echo ($users > 0) ? ($percents[1] = round(100 * ($tribes[1] / $users), 2))."%" : "---"; ?></td>
</tr>
<tr>
<td>Gauls</td>
<td><?php echo $tribes[2]; ?></td>
<td><?php $percents = 100*($tribes[2] / $users); echo $percents = intval ($percents); echo "%"; ?></td>
<td><?php echo ($users > 0) ? (100-$percents[0]-$percents[1])."%" : "---"; ?></td>
</tr>
</tbody>
</table>
+2 -5
View File
@@ -54,13 +54,10 @@ $top_rank = mysqli_fetch_assoc(mysqli_query($database->dblink,"SELECT username F
</tr>
<tr>
<td><b>Peace system</b></td>
<td><b>: <font color="Red"><?php
$peace_array=array("None","Normal","Christmas","New Year","Easter");
echo $peace_array[intval(PEACE)];
?></font></b></td>
<td><b>: <font color="Red"><?php echo (["None", "Normal", "Christmas", "New Year", "Easter"])[PEACE]; ?></font></b></td>
</tr>
<tr>
<td><b>Best Player</td>
<td><b>Best Player</b></td>
<td><b>: <font color="Red"><?php echo $top_rank['username'] ?></font></b></td>
</tr>
</table>
+1 -4
View File
@@ -53,10 +53,7 @@ $online = mysqli_query($database->dblink,"SELECT Count(*) as Total FROM " . TB_P
</tr>
<tr>
<td><b>Peace system</b></td>
<td><b>: <font color="Red"><?php
$peace_array=array("None","Normal","Christmas","New Year","Easter");
echo $peace_array[intval(PEACE)];
?></font></b></td>
<td><b>: <font color="Red"><?php echo (["None", "Normal", "Christmas", "New Year", "Easter"])[PEACE]; ?></font></b></td>
</tr>
</table>
</div>
+7 -43
View File
@@ -13,7 +13,7 @@
$tribe2 = mysqli_fetch_array(mysqli_query($database->dblink,"SELECT Count(*) as Total FROM ".TB_PREFIX."users WHERE tribe = 2"), MYSQLI_ASSOC);
$tribe3 = mysqli_fetch_array(mysqli_query($database->dblink,"SELECT Count(*) as Total FROM ".TB_PREFIX."users WHERE tribe = 3"), MYSQLI_ASSOC);
$tribes = array($tribe1['Total'], $tribe2['Total'], $tribe3['Total']);
$users = mysqli_fetch_array(mysqli_query($database->dblink,"SELECT Count(*) as Total FROM " . TB_PREFIX . "users WHERE tribe!=0 AND tribe!=4 AND tribe!=5"), MYSQLI_ASSOC);
$users = mysqli_fetch_array(mysqli_query($database->dblink,"SELECT Count(*) as Total FROM " . TB_PREFIX . "users WHERE tribe > 0 AND tribe < 4"), MYSQLI_ASSOC);
$users = $users['Total'];
?>
@@ -74,55 +74,19 @@
<tr>
<td>Romans</td>
<td><?php
echo $tribes[0]; ?></td>
<td>
<?php
if($users > 0){
$percents = 100 * (($tribes[0]) / $users);
echo $percents = intval($percents);
echo "%";
}else{
echo '---';
}
?>
</td>
<td><?php echo $tribes[0]; ?></td>
<td><?php echo ($users > 0) ? ($percents[0] = round(100 * ($tribes[0] / $users), 2))."%" : '---'; ?></td>
</tr>
<tr>
<td>Teutons</td>
<td><?php
echo $tribes[1]; ?></td>
<td><?php
if($users > 0){
$percents = 100 * ($tribes[1] / $users);
echo $percents = intval($percents);
echo "%";
}else{
echo '---';
}
?></td>
<td><?php echo $tribes[1]; ?></td>
<td><?php echo ($users > 0) ? ($percents[1] = round(100 * ($tribes[1] / $users), 2))."%" : "---"; ?></td>
</tr>
<tr>
<td>Gauls</td>
<td><?php
echo $tribes[2]; ?></td>
<td><?php
if($users > 0){
$percents = 100 * ($tribes[2] / $users);
echo $percents = intval($percents);
echo "%";
}else{
echo '---';
}
?></td>
<td><?php echo $tribes[2]; ?></td>
<td><?php echo ($users > 0) ? (100-$percents[0]-$percents[1])."%" : '---'; ?></td>
</tr>
</tbody>
</table>