Jump to content
MakeWebGames

Recommended Posts

Posted

well in my game stats page i get this error

 

Warning: Division by zero in /home/gangstal/public_html/stats.php on line 24

 

 

here is my script of Stats:

 

<?php
include "globals.php";
$q=$db->query("SELECT userid FROM users");
$membs=$db->num_rows($q);
$q=$db->query("SELECT userid FROM users WHERE bankmoney>-1");
$banks=$db->num_rows($q);
$q=$db->query("SELECT userid FROM users WHERE gender='Male'");
$male=$db->num_rows($q);
$q=$db->query("SELECT userid FROM users WHERE gender='Female'");
$fem=$db->num_rows($q);
$total=0;
$q=$db->query("SELECT money FROM users");
while($r=$db->fetch_row($q))
{
$total+=$r['money'];
}
$avg=(int) ($total/$membs);
$totalb=0;
$q=$db->query("SELECT bankmoney FROM users WHERE bankmoney>-1");
while($r=$db->fetch_row($q))
{
$totalb+=$r['bankmoney'];
}
$avgb=(int) ($totalb/$banks);
$totalc=0;
$q=$db->query("SELECT crystals FROM users");
while($r=$db->fetch_row($q))
{
$totalc+=$r['crystals'];
}
$totali=0;
$q=$db->query("SELECT inv_qty FROM inventory");
while($r=$db->fetch_row($q))
{
$totali+=$r['inv_qty'];
}
$avgc=(int) ($totalc/$membs);
$q=$db->query("SELECT mail_id FROM mail");
$mail=$db->num_rows($q);
$q=$db->query("SELECT evID FROM events");
$events=$db->num_rows($q);
print "<h3>Country Statistics</h3>
You step into the Statistics Department and login to the service. You see some stats that interest you.

<table width=75% cellspacing=1 class='table'> <tr> <th>Users</th><th>Money and Crystals</th></tr><tr><td>
There are currently $membs {$set['game_name']} players, $male males and $fem females.</td>  <td>
Amount of cash in circulation: \$".money_formatter($total,"").". 

The average player has: \$".money_formatter($avg,"").". 

Amount of cash in banks: \$".money_formatter($totalb,"").". 

Amount of players with bank accounts: $banks

The average player has in their bank accnt: \$".money_formatter($avgb,"").". 

Amount of crystals in circulation: ".money_formatter($totalc,"").". 

The average player has: ".money_formatter($avgc,"")." crystals.</td> </tr>
<tr> <th>Mails/Events</th><th>Items</th></tr><tr><td>
".money_formatter($mail,"")." mails and ".money_formatter($events,"")." events have been sent.</td> <td>
There are currently ".money_formatter($totali,"")." items in circulation.</td> </tr>
</table>";
$h->endpage();
?>

 

please help me out fix it...

Posted

Not the most ideal way to solve your problem, but can you simply do;

 

$q=$db->query("SELECT userid FROM users");
$membs=max($db->num_rows($q), 1);
$q=$db->query("SELECT userid FROM users WHERE bankmoney>-1");
$banks=max($db->num_rows($q), 1);
$q=$db->query("SELECT userid FROM users WHERE gender='Male'");
$male=max($db->num_rows($q), 1);
$q=$db->query("SELECT userid FROM users WHERE gender='Female'");
$fem=max($db->num_rows($q), 1);

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...