作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在将 Rgraph 与 PHP 和 MySQL 数据集成时遇到问题。我遵循了 Rgraph 网站的说明。
在 Rgraph 站点上,该示例使用数组数据,但我的案例不使用数组。我想显示有多少 pegawai 参加了一个月。
<?php
$query2 = "SELECT count(id_absensi) AS jumhadir FROM absensi WHERE nip_pegawai = '123040269'";
if($query2){
$data = array();
while ($row = mysql_fetch_assoc($query2)){
$data[] = $row["jumhadir"];
}
$data_string = "[".join(",", $data)."]";
} else {
print('MySQL query failed with error : '.mysql_error());
}
?>
<html>
<head>
<!-- Don't forget to update these paths -->
<script src="libraries/RGraph.common.core.js" ></script>
<script src="libraries/RGraph.line.js" ></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="js/jquery-1.11.3.min.js"></script>
</head>
<body>
<canvas id="cvs" width="600" height="250">[No canvas support]</canvas>
<script>
chart = new RGraph.Line({
id: 'cvs',
data: <?php print($data_string) ?>,
options: {
gutterLeft: 35,
gutterRight: 5,
hmargin: 10,
tickmarks: 'endcircle',
labels: <?php print("Kehadiran") ?>
}
}.draw()
</script>
</body>
</html>'
我没有收到任何错误,也没有图表。我错过了什么?
最佳答案
这个:
$query2 = "SELECT count(id_absensi) AS jumhadir FROM absensi WHERE nip_pegawai = '123040269'";
不运行查询 - 它只是一个包含 SQL 语句的字符串。所以您可以尝试将其更改为:
$sql = "SELECT count(id_absensi) AS jumhadir FROM absensi WHERE nip_pegawai = '123040269'";
$query2 = mysql_query($sql);
if ($query2) {
// ...
当然,在您进行查询之前,您必须连接到您的数据库:
$connection = mysql_connect('localhost', 'username', 'password');
mysql_select_db('myDatabase');
关于php - 如何将 Rgraph 与 PHP 和 MySQL 集成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34010898/
我是一名优秀的程序员,十分优秀!