Thanks for your reply, let me elaborate: there are 14 questions in this little survey.
PHP reads the answers from a table and increases the count value for each possible answer in a table called surveyU6_3_totals.
If PHP finds answer A for Q1, it increases the value in row Q1, column A1_total by +=1
That way, I get the totals of each reply for all participants in the survey and all possible answers.
surveyU6_3_totals has the columns:
id, Qnr, A1_total, A2_total, A3_total, A4_total, A5_total, A6_total, A7_total
and it has rows Q1 to Q14, for the 14 questions.
So I collect the data with:
$numname[ ] = array(
$row['Qnr'],
$row['A1_total'],
$row['A2_total'],
$row['A3_total'],
$row['A4_total'],
$row['A5_total'],
$row['A6_total'],
$row['A7_total'],
$count
);
$count is the total number of participants in the survey, a few hundred, taken from the table where the results are stored.
'SELECT COUNT(*) FROM surveyU6_3_data'
This displays the total number of answers for each question and possible answer correctly:
<?php foreach ($numname as $data): ?>
<p>
<tr>
<td> <?php echo htmlspecialchars($data[0], ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars($data[1], ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars($data[2], ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars($data[3], ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars($data[4], ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars($data[5], ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars($data[6], ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars($data[7], ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars($data[8], ENT_QUOTES, 'UTF-8'); ?> </td>
<tr>
</p>
<?php endforeach; ?>
data[0] is the question number, like Q1, data[8] is $count.
Anway, I fixed it now: I made:
$numnameP[] = array(
$row['Qnr'],
$row['A1_total']/$count*100,
$row['A2_total']/$count*100,
$row['A3_total']/$count*100,
$row['A4_total']/$count*100,
$row['A5_total']/$count*100,
$row['A6_total']/$count*100,
$row['A7_total']/$count*100,
$count
);
and then:
<?php foreach ($numnameP as $data): ?>
<p>
<tr>
<td> <?php echo htmlspecialchars($data[0], ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars(intval($data[1]), ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars(intval($data[2]), ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars(intval($data[3]), ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars(intval($data[4]), ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars(intval($data[5]), ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars(intval($data[6]), ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars(intval($data[7]), ENT_QUOTES, 'UTF-8'); ?> </td>
<td> <?php echo htmlspecialchars($data[8], ENT_QUOTES, 'UTF-8'); ?> </td>
<tr>
</p>
<?php endforeach; ?>
I am not very proficient with this stuff, so I am not sure why the percent values did not show up!
Works now!!