-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_report.php
86 lines (62 loc) · 2.32 KB
/
product_report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!doctype html >
<html>
<head>
<title>Product report</title>
<link href="css/reports.css" type="text/css" rel="stylesheet">
</head>
<body>
<a href="offer_report.php"><button class="btn" name="add">Offer Report</button></a>
<?Php
require "config.php";// Database connection
if($stmt = mysqli_query($conn,("SELECT Month,target, sales FROM product_report"))){
echo "No of records : ".mysqli_num_rows($stmt)."<br>";
$php_data_array = Array(); // create PHP array
//$row2 = mysqli_fetch_array($stmt,MYSQLI_NUM);
echo "<table>
<tr> <th>Month</th><th>Target</th><th>Sales</th></tr>";
while ($row = mysqli_fetch_row($stmt)) {
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>";
$php_data_array[] = $row; // Adding to array
}
echo "</table>";
}else{
echo mysqli_error();
}
//print_r( $php_data_array);
// You can display the json_encode output here.
// echo json_encode($php_data_array);
// Transfor PHP array to JavaScript two dimensional array
echo "<script>
var my_2d = ".json_encode($php_data_array)."
</script>";
?>
<div id="chart_div"></div>
<br><br>
<!-- <a href=https://www.plus2net.com/php_tutorial/chart-column-database.php>Column Chart from MySQL database</a> -->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load the Visualization API and the corechart package.
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawChart); //draw chart
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Month');
data.addColumn('number', 'Target');
data.addColumn('number', 'Sale');
for(i = 0; i < my_2d.length; i++)
data.addRow([my_2d[i][0], parseInt(my_2d[i][1]),parseInt(my_2d[i][2])]);
var options = {
title: 'Product sales report',
hAxis: {title: 'Month', titleTextStyle: {color: '#333'}},
vAxis: {minValue: 0},
width:500,
height:400
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
//////
</script>
</body>
</html>