timmah1 Posted June 21, 2008 Share Posted June 21, 2008 ok, I have three items in the database group01 group02 totalgroup group01 must total totalgroup group02 must total totalgroup What i'm trying to do is make a percentage from 0-100%, but both groups must equal the totalgroup for it to be 100% So, if totalgroup equals 100 than group01 and group02 must each equal 100 Then I take group01 and group02, add them together, then divide by totalgroup to give me a percentage of 0%-100%. The problem I'm having is if totalgroup equals 200, and group01 equals 200 and group02 equals 0, it still shows 100%, and it shouldn't because group02 must equal totalgroup. Does this make sense? The code I'm using now is this if($row1['group01] = $totalgroup) { $totaloverall= $row1['group01']; } else { $totaloverall = $row1['group01] / $totalgroup; } if($row1['group02] = $totalgroup) { $totaloverall01= $row1['group02']; } else { $totaloverall01 = $row1['group02] / $totalgroup; } Then this $total = $totaloverall+$totaloverall01; $number = round(($total / $totalgroup) * 100) ; if($number < 0 ) $number = 0 ; if($number > 100) $number = 100 ; Can anybody help me out here? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Stephen Posted June 21, 2008 Share Posted June 21, 2008 Why don't you go group 01 + group 02 / 2 = totalgroup, or something like that. If group 01 is 200 and group 2 is 200 it would be 200. Quote Link to comment Share on other sites More sharing options...
timmah1 Posted June 21, 2008 Author Share Posted June 21, 2008 Yes, that works, and I've tried that, but happens is if totalgroup = 200 and group01 = 200 and group02 =0, the total is still 100%, and it shouldn't be because group02 has to equal totalgroup as well Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 Add an if ($row['group01'] == $totalgroup && $row['group2'] == $totalgroup) line or something. O_O P.S: In your script that you showed us, you're using = instead of ==, so it'll always be true. =) Quote Link to comment Share on other sites More sharing options...
Stephen Posted June 21, 2008 Share Posted June 21, 2008 Yes, that works, and I've tried that, but happens is if totalgroup = 200 and group01 = 200 and group02 =0, the total is still 100%, and it shouldn't be because group02 has to equal totalgroup as well $totalnum=200; $group1=200; $group2=0; $grouptotal=group1+group2; $grouptotal=$grouptotal/2; $grouptotal=$grouptotal/$totalnum; $grouptotal=$grouptotal*100; That would be 50%. Of course I think if group1 = 100, group2=200, and totalnum = 300 it would be 100% and thats not what you want. Maybe like: $group1=100; $group2=300; $totalnum=400; $totalnumdiv=$totalnum/2; if ($group1==$totalnumdiv && $group2==$totalnumdiv) { echo("Group1 and group2 are the same number and equal to totalnum."); } else { echo("Group1 and group2 are not the same number but may be equal to totalnum."); //This is what it should return. } I think that should work. Try it with group1 and group2 equaling 200. Quote Link to comment Share on other sites More sharing options...
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.