Nodral Posted September 21, 2010 Share Posted September 21, 2010 Hi all I have several arrays set, and I can guarantee I have values in these as I have tested them by echoing out each value. However, when I pass it through a user defined function to produce a percentage for each value of the total arry, I get a null return. I don't even get any errors. Any ideas? // Produce the % array of each array for use in 2nd report $percent_morale1=percentCalc($morale_count1[1],$morale_count1[2],$morale_count1[3],$morale_count1[4],$morale_count1[5],$total_morale1); $percent_morale2=percentCalc($morale_count2[1],$morale_count2[2],$morale_count2[3],$morale_count2[4],$morale_count2[5],$total_morale2); $percent_morale3=percentCalc($morale_count3[1],$morale_count3[2],$morale_count3[3],$morale_count3[4],$morale_count3[5],$total_morale3); $percent_morale4=percentCalc($morale_count4[1],$morale_count4[2],$morale_count4[3],$morale_count4[4],$morale_count4[5],$total_morale4); $percent_morale5=percentCalc($morale_count5[1],$morale_count5[2],$morale_count5[3],$morale_count5[4],$morale_count5[5],$total_morale5); $percent_morale6=percentCalc($morale_count6[1],$morale_count6[2],$morale_count6[3],$morale_count6[4],$morale_count6[5],$total_morale6); <?php function percentCalc($value1,$value2,$value3,$value4,$value5,$total) { $array=array($value1,$value2,$value3,$value4,$value5); while (list($key,$arraycontent)= each($array)) { $c_percent=(($arraycontent/$total)*100); $final_array[]=$c_percent; } return $final_array; } ?> <?php echo"<td class=\"percent1\" > "; printf("%01.0f",$percent_morale1[1]); echo "%</td>"; echo"<td class=\"percent2\" > "; printf("%01.0f",$percent_morale1[2]); echo "%</td>"; echo"<td class=\"percent3\" > "; printf("%01.0f",$percent_morale1[3]); echo "%</td>"; echo"<td class=\"percent4\" > "; printf("%01.0f",$percent_morale1[4]); echo "%</td>"; echo"<td class=\"percent5\" > "; printf("%01.0f",$percent_morale1[5]); echo "%</td>"; ?> Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted September 21, 2010 Share Posted September 21, 2010 how about a sample of the data contained in the arrays. It looks like the list might not be working the way you want and since final_array is only defined in your list section. final_array doesn't contain anything. Quote Link to comment Share on other sites More sharing options...
Nodral Posted September 21, 2010 Author Share Posted September 21, 2010 When I echo the data out of the basic arrays, I get the following. $morale_count1[1] = 1 $morale_count1[2] = 1 $morale_count1[3] = 0 $morale_count1[4] = 0 $morale_count1[5] = 0 $total_morale1 = 2. I have another report set up which just produces the raw data and this works fine, it's just the % conversion which is not working. Quote Link to comment Share on other sites More sharing options...
Nodral Posted September 21, 2010 Author Share Posted September 21, 2010 Any ideas anyone??? It's got me totally stumped!!! Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted September 21, 2010 Share Posted September 21, 2010 With your example I get: <td class="percent1" > 50%</td> Quote Link to comment Share on other sites More sharing options...
mikosiko Posted September 21, 2010 Share Posted September 21, 2010 for a start PHP arrays elements numbering start at 0 not in 1, and that could be the reason for some errors I get a null return for null you mean a blank screen or null result values ? add this lines to your code and test if you get some error : (if I'm guessing correctly about a second option for your errors maybe you could see a nasty error here ) ini_set("display_errors", "1"); error_reporting(E_ALL); // Produce the % array of each array for use in 2nd report $percent_morale1=percentCalc($morale_count1[1],$morale_count1[2],$morale_count1[3],$morale_count1[4],$morale_count1[5],$total_morale1); $percent_morale2=percentCalc($morale_count2[1],$morale_count2[2],$morale_count2[3],$morale_count2[4],$morale_count2[5],$total_morale2); $percent_morale3=percentCalc($morale_count3[1],$morale_count3[2],$morale_count3[3],$morale_count3[4],$morale_count3[5],$total_morale3); $percent_morale4=percentCalc($morale_count4[1],$morale_count4[2],$morale_count4[3],$morale_count4[4],$morale_count4[5],$total_morale4); $percent_morale5=percentCalc($morale_count5[1],$morale_count5[2],$morale_count5[3],$morale_count5[4],$morale_count5[5],$total_morale5); $percent_morale6=percentCalc($morale_count6[1],$morale_count6[2],$morale_count6[3],$morale_count6[4],$morale_count6[5], 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.