criminal wars Posted January 31, 2011 Posted January 31, 2011 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... Quote
Danny696 Posted January 31, 2011 Posted January 31, 2011 Noone has a bank yet, the error will go when they do. Quote
Blade Maker Posted January 31, 2011 Posted January 31, 2011 Try: $avgb=int($totalb/$banks); idk I will check this in a second brb. Quote
Diesl Posted January 31, 2011 Posted January 31, 2011 You don't have any users with bank money (or bank accounts) as seen in lines 4-5. So $banks is equal to 0. Quote
Blade Maker Posted January 31, 2011 Posted January 31, 2011 OK back the above post was wrong so hold on. Edit: I just looked through the code and Diesl is correct. Quote
criminal wars Posted January 31, 2011 Author Posted January 31, 2011 can you give me a fixed one please i would appreicate it :) Quote
Blade Maker Posted January 31, 2011 Posted January 31, 2011 Reply to my message and yeah I will. Quote
criminal wars Posted January 31, 2011 Author Posted January 31, 2011 i sent a PM back now prove to me the i will hire you tommorow Quote
Diesl Posted January 31, 2011 Posted January 31, 2011 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); Quote
Blade Maker Posted January 31, 2011 Posted January 31, 2011 Sorta correct, but yeah you have to make it take something from the database, and make sure it has a number. Quote
criminal wars Posted January 31, 2011 Author Posted January 31, 2011 well lol it was a bit of nooby thing from me i fixed all i had to do was open a bank account also just wannated to know i have like 21 items ATM but says 2 item in circulation Quote
Blade Maker Posted January 31, 2011 Posted January 31, 2011 Is the Limit set to 2 or something. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.