#15214 - 07/23/07 06:24 AM
Division By Zero.
|
HarleyJ
Malt-o-Meal
Registered: 07/23/07
Posts: 1
|
Offline
|
|
I noticed this error on my index.php page before you login.
Warning: Division by zero in /home/flashmor/public_html/valhallen/lib.php on line 208
Warning: Division by zero in /home/flashmor/public_html/valhallen/lib.php on line 210
The selected text for the Errors specified were:
$stathp = ceil($userrow["currenthp"] / $userrow["maxhp"] * 100); if ($userrow["maxmp"] != 0) { $statmp = ceil($userrow["currentmp"] / $userrow["maxmp"] * 100); } else { $statmp = 0; } $stattp = ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);
I cannot see an error at all, If there is something that I cannot see, it would be greatfull for a fix as users using IE get the error: page cannot be displayed, only top level element is allowed
Appreciated =)
|
|
Top
|
|
|
#15224 - 07/23/07 05:48 PM
Re: Division By Zero.
[Re: Fayt]
|
AnmanIndustries
Cookie Crisp
   
Registered: 03/21/05
Posts: 2876
Loc: Planet Stupid, AKA Earth
|
Offline
|
|
You say this apears before you log in? Funny that, this is no part of the STOCK CODE anymore, as the lines you have shown us, do NOT apear before you log in.
Thread moved.
Here is your problem
Can someone please tell me what the problem with this is:
$stathp = ceil($userrow["currenthp"] / $userrow["maxhp"] * 100); if ($userrow["maxmp"] != 0) { $statmp = ceil($userrow["currentmp"] / $userrow["maxmp"] * 100); } else { $statmp = 0; } $stattp = ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);
No need to, I already know the problem. $userrow["currenthp"] $userrow["maxhp"] $userrow["maxmp"] userrow["currenttp"] userrow["maxtp"] and whatever use has USER ROW in it.
Can any one tell me what the USERROW is? Thats right children. It is the array that stores all the LOGED IN users character info.
What happens, when you state a variable, that hasnt been said? Wow children, you sure KNOW HOW TO CODE PHP, because you are absolutly right. If you DONT set a variable, the variable is EMPTY. Or, in the case of a number check, it is 0.
So, if youre not logged in, and you have varialbes that are SUPPOSE to have numbers, and you try to devide a number by 0... this is the error you are getting.
|
|
Top
|
|
|
#15231 - 07/24/07 04:37 AM
Re: Division By Zero.
[Re: Fayt]
|
AnmanIndustries
Cookie Crisp
   
Registered: 03/21/05
Posts: 2876
Loc: Planet Stupid, AKA Earth
|
Offline
|
|
negative numbers are dividable.
|
|
Top
|
|
|
#15235 - 07/24/07 07:53 PM
Re: Division By Zero.
[Re: Fayt]
|
AnmanIndustries
Cookie Crisp
   
Registered: 03/21/05
Posts: 2876
Loc: Planet Stupid, AKA Earth
|
Offline
|
|
Nothing can be devided by 0. But -1 can be devided by -1 and so on. Basicly, we are both right. I was just more right than you. Like communism.
Any number, regardless if it is negative or not, can be devided with another number, that is not 0. end of story.
|
|
Top
|
|
|
#15527 - 08/30/07 10:32 AM
Re: Division By Zero.
[Re: Fayt]
|
CBeTHaX
Malt-o-Meal
Registered: 08/24/07
Posts: 8
|
Offline
|
|
All this can be accomplished by writing @ in front of a function. In this case it will be:
$stathp = @ceil($userrow["currenthp"] / $userrow["maxhp"] * 100);
if ($userrow["maxmp"] != 0) { $statmp = @ceil($userrow["currentmp"] / $userrow["maxmp"] * 100); } else { $statmp = 0; }
$stattp = @ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);
The other way to not get an error is to write the following function on the top of index.php after <?php :
|
|
Top
|
|
|
|
|