I have an output.php webpage to display the results of a survey.
For each question, the page shows a table with the number of answers for each gender and choice. Works fine, displays correctly.
Beneath that is another table which should display the % values for each gender and choice.
I can’t see what is wrong, but I cannot get the correct % values in the % table.
If I set this in the code below:
${"menP$i"}[$j][$key] = 55.55;
Then all the values in the % tables show up as 55.55, but when I try to use my $percent variable, I get zero where I should have a number or 100% where it should be less.
${"menP$i"}[$j][$key] = $percent;
If I echo $percent to the screen, it has the correct values, but $percent will not go correctly in my
${"menP$i"}[$j][$key]
I can’t see why not, because, if I use a number, there is no problem!
For say, Q1 row 1 I get this echo output, which is correct:
$percent is 33
$percent is 0
$percent is 67
$percent is 0
$percent is 100
Any tips or pointers as to what I am doing wrong please??
${"menP$i"} = displayAllQs($Qnr);
$lenmenP = count(${"menP$i"});
//echo '$lenmenP is ' . $lenmenP;
//exit();
for($j=0; $j < $lenmenP; ++$j) {
foreach(${"menP$i"} as $data) {
//print_r($data) . '<br>';
//echo '<br>';
foreach ($data as $key=>$value) {
//echo '$key is ' . $key . '<br>';
//echo '$value is ' . $value . '<br>';
if(is_int($value)) {
$Totals = $data['Totals'];
$percent = round($value/$Totals, 2)*100;
echo '$percent is ' . $percent . '<br>';
//$data[$key] = $percent;
//${"menP$i"}[$j][$key] = $percent;
${"menP$i"}[$j][$key] = 55.55;
//echo '${"menP$i"}[$j][$key] is ' . ${"menP$i"}[$j][$key] . '<br>';
}
}
}
}
print_r(${"menP$i"}) . '<br>';
echo '<br>';