-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart.php
161 lines (144 loc) · 4.59 KB
/
chart.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!doctype html>
<?php
if(isset($_COOKIE["access"])){
// Connect to MySQL.
require ('mysql_connect.php');
// Connect to the Database
// Name for the Database
$d = "bardwangsql";
// Make the query:
$q = "SELECT * FROM $d.product";
$r = mysql_query ($q); // Run the query.
$regulartea = 0;
$puerhtea = 0;
$teapot = 0;
// Fetch and print all the records:
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
if($row['productcategory'] == 'regular_tea'){
$regulartea = $regulartea + 1;
}
else if($row['productcategory'] == 'pu-erh_tea'){
$puerhtea = $puerhtea + 1;
}
else {
$teapot = $teapot + 1;}
}
// Make the query:
$q = "SELECT * FROM $d.order2";
$r = mysql_query ($q); // Run the query.
// to get an array of order numbers
$array = array();
// Fetch and print all the records:
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
if(!isset($array[$row['ordername']])){
$array[$row['ordername']] = $row['quantity'];
}
else {
$array[$row['ordername']] = $array[$row['ordername']] + $row['quantity'];
}
}
}
else{
printf("<script>location.href='adminaccess.php'</script>");
}
?>
<?php
echo "<div class='welcome'>Welcome Admin</div>";
?>
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
google.setOnLoadCallback(drawChart2);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Regular Tea', <?php echo $regulartea ;?>],
['Pu-erh Tea', <?php echo $puerhtea ;?>],
['Teapot', <?php echo $teapot ;?>],
]);
// Set chart options
var options = {'title':'Types of Chinese Tea',
'width':600,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart2() {
var rows = new Array();
<?php foreach($array as $key => $val){ ?>
rows.push(['<?php echo $key; ?>', <?php echo $val; ?>]);
<?php } ?>
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Quantity');
data.addRows(rows);
// Set chart options
var options = {title:'Customer Order History',
hAxis: {title: 'Category', titleTextStyle: {color: 'red'}},
vAxis: {maxValue: 1},
width:600,
height:300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.BarChart(document.getElementById('chart2_div'));
chart.draw(data, options);
}
</script>
<meta charset="utf-8">
<link rel="stylesheet" href="Springtea.css">
<script src="files/jquery.min.js"></script>
<script src="files/jquery.validate.min.js"></script>
<script src="files/validation.js"></script>
<script src="files/login.js"></script>
<title>Spring Tea - My Chart</title>
</head>
<body>
<h1><em>Spring Tea - My Chart</em></h1>
<div class ="navbar">
<ul>
<li><a href="Springtea.php">Home</a></li>
<li class="confirm"><a href="account.php">Your Account</a>
<ul class="subnavbar">
<li><a href="confirmation.php">Your Orders</a></li>
</ul>
</li>
<li><a href="teainfo.php">Tea Info</a>
<ul class="subnavbar">
<li><a href="regular_tea.php">Regular Tea</a></li>
<li><a href="pu-erh_tea.php">Pu-erh Tea</a></li>
<li><a href="teapot.php">Teapot</a></li>
</ul>
</li>
<li class="order"><a href="cart.php">Cart</a>
</li>
<li><a href="contact_info.php">Contact Info</a></li>
</ul>
</div>
<br><br><br><br><br>
<fieldset>
<h1 class="info">My Chart</h1>
<div id="chart_div"></div>
<div id="chart2_div"></div>
<h1 class="info"><a class= 'back' href='admin.php'>Go to Admin</a></h1>
</fieldset>
<hr>
<p class="red"><a href="Credit.html">Credits</a>
</p>
</body>
</html>