Chartjs-I need a PHP query to grab data from the database and use in my bar charts for results

1👍

Generally, what you have is correct, I tend to write my queries seperate from the chart to maintain seperation; eg:

<?php
$query="SELECT * FROM checkPointMod";
# echo $query;
$newArray = array();
$result = $conn->query($query);
while($row = $result -> fetch_assoc());  {
    $newArray[] = $row['mod1'];
    $newArray[] = $row['mod2'];
    $newArray[] = $row['mod3'];
    $newArray[] = $row['mod4'];
    $newArray[] = $row['mod5'];
}
$conn -> close();
?>

You can do a print_r to check the content of your array, if need be …

Then in your chart section:

 data: [<?= $newArray ?>],

Hope that helps you get on you way …

Leave a comment