如何将Rgraph与PHP和MySQL集成?
我在将Rgraph与PHP和MySQL数据集成时遇到问题。我按照Rgraph网站的指示进行操作 在Rgraph站点上,示例使用数组数据,但我的案例不使用数组。 我想显示一个月有多少pegawai参加如何将Rgraph与PHP和MySQL集成?,php,mysql,rgraph,Php,Mysql,Rgraph,我在将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 (
<?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>'
这是:
不运行查询-它只是一个包含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');
$connection = mysql_connect('localhost', 'username', 'password');
mysql_select_db('myDatabase');