I have these answers from my database but I think it's in a array because when I want to put it in my chart it selects the last one and not 1 by 1.
I tried putting the chart in the while loop but it didn't work then. Even though it does work with the echo of it.
This is the script:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Task', 'Hours per Day'],
['A', <?php echo $count; ?>],
['B', <?php echo $count; ?>],
['C', <?php echo $count; ?>],
['D', <?php echo $count; ?>],
['E', <?php echo $count; ?>],
['F', <?php echo $count; ?>]
]);
var options = {
title: 'Aantal antwoorden:'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
And this is how I get the variables:
$aantal = $row['count(answer_id)'];
for ($meme = 1; $meme <= $aantal; $meme++) {
$countAnswerQuery = "SELECT answer_id, COUNT(*), question_id FROM survey_answers WHERE question_id = '$meme' GROUP BY answer_id ORDER BY question_id ASC";
$countanswerresult = mysqli_query($conn, $countAnswerQuery);
if ($countanswerresult ->num_rows > 0) {
while ($row = mysqli_fetch_array($countanswerresult)) {
$question = $row['question_id'];
$answer = $row['answer_id'];
$count = $row['COUNT(*)'];
I hope to be able to put the variable in and that it changes value just like in the echo ( that I didn't include ).
This is the DB table
and this is the count query in phpmyadmin: