Page 1 of 1

problem with dont know what..

Posted: Sat Feb 14, 2004 10:51 am
by Citizen99
This script prints error: Division by zero...
or <TD>000000000000000000000-2</TD>.. in source code of page. But none of these value is 0.

Code: Select all

for ($i=1; $i<5; $i++) {

print "<TR align=center><TD>$i</TD>";
print "<TD>";

  $sql="SELECT COUNT(status) from typy where stawka=$i AND status NOT LIKE 'pending'";
  $wynik = mysql_query($sql) or die(sql_error);

   while ($row = mysql_fetch_row($wynik)) {
   $all=$row[0];
   print $all;
}

print "</TD><TD>";

  $sql="SELECT COUNT(status) from typy where stawka=$i AND status like 'win'";
  $wynik = mysql_query($sql) or die(sql_error);

   while ($row = mysql_fetch_row($wynik)) {
   $win=$row[0];
   print $win;
}

print "</TD><TD>";

   $skut=($win/$all*100);
   print round($skut,2)."%";

      }

print "</TD><TD>";

  $sql_moc="SELECT SUM(kurs*stawka) from typy where stawka=$i AND status like 'win'";
  $wynik = mysql_query($sql_moc) or die(sql_error);

   while ($row = mysql_fetch_row($wynik)) {
   $wygrana=round($row[0],2);
}

  $sql="SELECT SUM(stawka) from typy where stawka=$i";
  $wynik = mysql_query($sql) or die(sql_error);

   while ($row = mysql_fetch_row($wynik)) {
   $wklad=$row[0];
}
   $prof=($wygrana-$wklad);
   print $prof;

print "</TD><TD>";
 
if ($wklad==0 || $wygrana==0)
    {
	print "0%";
    }

 else {
   $zysk=(($wygrana/$wklad)*100-100);
   print round($zysk,2)."%";

      }

print "</TD></TR>";

}

Re: problem with dont know what..

Posted: Sat Feb 14, 2004 11:03 am
by Straterra
Citizen99 wrote:In line I wrote down script prints: Errors it`s connected with change I have made: smth -> smth.$i cause i want to add it later. None of these value is 0.. but i see only 000000000000000000000-2 or smth like Error: Division by zero...
Um...I don't understand what you are saying or what the problem is..What lines are you getting errors on?

Posted: Sat Feb 14, 2004 11:04 am
by Illusionist
... little more information... Like waht is teh error, what line is it comming from, speak in plain english, i dont understand a word you said

Posted: Sat Feb 14, 2004 11:09 am
by Citizen99
In line $skut=($win/$all*100);

Posted: Sat Feb 14, 2004 11:13 am
by Straterra
What does this line do?

Code: Select all

$skut="$skut".$i;
I mean, right after that line you are giving $skut a new value. A new value which does nothing with the old one..so, I am curious..What is it's purpose?

Posted: Sat Feb 14, 2004 11:18 am
by Citizen99
I want to add all values from 1 to 5 skut.$i ... like 10+2+31+4+45.. Can I add them in other way ?;]

Posted: Sat Feb 14, 2004 11:19 am
by Illusionist
also curious as to why you do that everytime. On all the vars after you do .$i you always give them a new value that has nothing to do with the previous line....

Posted: Sat Feb 14, 2004 11:20 am
by Straterra
Hm...I also see that since you do do the same things over and over again...You should consider writing a function instead of the way it is right now.

Posted: Sat Feb 14, 2004 11:20 am
by Illusionist
then i think you might just want to do

Code: Select all

$skut += $skut;
And put that after you do the other math stuff.

Posted: Sat Feb 14, 2004 11:22 am
by Citizen99
ok I will try. I write it like:

{
$skut=($win/$all*100);
print round($skut,2)."%";
$skut+=$skut;

and after everything

}

print $skut;

I have value skut=71,83,30,43,96.5 he prints 193.....

I nedd to add everything...

Posted: Sat Feb 14, 2004 11:37 am
by Straterra
Am I the only one who is TOTALLY lost here?

Posted: Sat Feb 14, 2004 11:47 am
by Illusionist
no, i'm lost too... i have no idea what your trying to do. Citizen do you speak American English?

Posted: Sat Feb 14, 2004 11:53 am
by Citizen99
I will try one more time :]

1) I want to count $skut, there are 4 values (for $i=1 $i=2 $i=3 $i=4)
2) So I want give name for each $skut like: $skut.$i ($skut1,$skut2,$skut3,$skut4)
3) Then I want to add it all to get one result.

But its not working or error: Division by zero appear when I use $skut.$i, $prof.$i, etc in code.

Posted: Sat Feb 14, 2004 7:41 pm
by Citizen99
Ok everything works fine :]

instead $skut+=skut; I use $boo+=$skut; and script adds everything ;P

Sory for the sentences from the begining too fast thinking too much beer.. but I still have to work with my English :]

Posted: Sat Feb 14, 2004 10:51 pm
by m3mn0n
I understand the problem just fine.

Like in any math situation, you can't divide by zero. If PHP catches a script doing so, it will hault execution and display that error.

What I use to do to avoid this was add 1 any place a variable was to be divided and then subtract 1 on the next line. This would then give you 0 as an answer instead of that error.