Jump to content
MakeWebGames

Division by zero error when moving the "users stats" into the mainmenu.php


DesignLoft

Recommended Posts

Well now i'm out of the beta phase I decided to make it more user friendly and i thought to place the users stats, like brave etc.. into the main menu. like on monocountry. so i copy this code over as it is required:

function userdata($ir,$lv,$fm,$cm,$dosessh=1)
$enperc=(int) ($ir['energy']/$ir['maxenergy']*100);
$wiperc=(int) ($ir['will']/$ir['maxwill']*100);
$experc=(int) ( $ir['exp']/$ir['exp_needed']*100);
$brperc=(int) ($ir['brave']/$ir['maxbrave']*100);
$hpperc=(int) ($ir['hp']/$ir['maxhp']*100);
$enopp=100-$enperc;
$wiopp=100-$wiperc;
$exopp=100-$experc;
$bropp=100-$brperc;
$hpopp=100-$hpperc;
$d="";

 

and then where appropriate i add

print "
[b]Your Stats[/b]

[b]Energy:[/b] {$enperc}%



[b]Will:[/b] {$wiperc}%



[b]Brave:[/b] {$ir['brave']}/{$ir['maxbrave']}



[b]EXP:[/b] {$experc}%



[b]Health:[/b] {$hpperc}%


 

then the error appears as:

 

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 2

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 3

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 4

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 5

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 6

any ideas why? I know php doesn't allow division by zero as it is impossible. But since i copied it over from header.php where it was working i cannot see why?

Link to comment
Share on other sites

  • 3 years later...
Well now i'm out of the beta phase I decided to make it more user friendly and i thought to place the users stats, like brave etc.. into the main menu. like on monocountry. so i copy this code over as it is required:
function userdata($ir,$lv,$fm,$cm,$dosessh=1)
$enperc=(int) ($ir['energy']/$ir['maxenergy']*100);
$wiperc=(int) ($ir['will']/$ir['maxwill']*100);
$experc=(int) ( $ir['exp']/$ir['exp_needed']*100);
$brperc=(int) ($ir['brave']/$ir['maxbrave']*100);
$hpperc=(int) ($ir['hp']/$ir['maxhp']*100);
$enopp=100-$enperc;
$wiopp=100-$wiperc;
$exopp=100-$experc;
$bropp=100-$brperc;
$hpopp=100-$hpperc;
$d="";

 

and then where appropriate i add

print "
Your Stats

Energy: {$enperc}%



Will: {$wiperc}%



Brave: {$ir['brave']}/{$ir['maxbrave']}



EXP: {$experc}%



Health: {$hpperc}%


 

then the error appears as:

 

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 2

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 3

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 4

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 5

Warning: Division by zero in /usr/home/ben/public_html/mafia/mainmenu.php on line 6

any ideas why? I know php doesn't allow division by zero as it is impossible. But since i copied it over from header.php where it was working i cannot see why?

The variables here are being assigned values by the "include globals.php" in the header file. so after you have cut it out from the header it's not going to be assigned any value there for 0 is assigned.

Link to comment
Share on other sites

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...