Jump to content

Recommended Posts

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?

 

:wtf:

 

// 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>";
	?>

Link to comment
https://forums.phpfreaks.com/topic/213985-why-nothing-happening/
Share on other sites

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.

 

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],

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.