PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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>";
}
Last edited by Citizen99 on Sat Feb 14, 2004 7:43 pm, edited 3 times in total.
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?
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?
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....
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.
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.