我设法让PHP和JavaScript代码在同一页面上运行。在左侧页面的顶部,您可以看到我的php表中的数据正在被正确地拉出来,但是,当我将php代码粘贴到表'数据'需要保留的位置时,它就是'即使在php标签中包围,也可以工作。
$conn = mysqli_connect("localhost", "x", "y", "z");
$query = "SELECT * FROM `checkPointMod`";
$result = $conn -> query($query);
while($row = $result -> fetch_assoc())
{
echo $row['mod1']."
";
echo $row['mod2']."
";
echo $row['mod3']."
";
echo $row['mod4']."
";
echo $row['mod5']."
";
echo $row['mod6']."
";
}
$conn -> close();
?>
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [<?php echo $row['mod1']?>, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
更新: - 我去检查元素,看看输出是什么,它在这里看到,我也放置mod2,看看是否会出现6 ...