Download presentation
Presentation is loading. Please wait.
1
PHP Graph
2
Files Create 3 files and 3 tables
Include.php for connect PHP and database canvasjs.min.js for Java script graph.php for show graph Table Employee Table Order Table Order_detail
3
Create table Employee CREATE TABLE `employee` ( `employee_id` int(11) NOT NULL auto_increment, `employee_name` varchar(100) NOT NULL, `employee_sex` varchar(6) NOT NULL, `employee_tle` varchar(15) NOT NULL, `employee_address` varchar(255) NOT NULL, PRIMARY KEY (`employee_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
4
Insert data into employee
INSERT INTO `employee` VALUES (1, 'John', 'Male', ' ', '451 prajinburi'); INSERT INTO `employee` VALUES (2, 'Somsri', 'Male', ' ', '12 moo1 rungsit'); INSERT INTO `employee` VALUES (3, 'Somsak', 'Male', ' ', '23/2 phaholyotin'); INSERT INTO `employee` VALUES (4, 'Somchai', 'Female', ' ', '11/1 rungsit'); INSERT INTO `employee` VALUES (5, 'Sommai', 'Male', ' ', '123/1 ladpakao');
5
Create table Order CREATE TABLE `order` ( `order_ID` varchar(100) NOT NULL, `order_date` date NOT NULL, `customer_id` int(11) NOT NULL, `employee_id` int(11) NOT NULL, PRIMARY KEY (`order_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
6
Insert data into Order INSERT INTO `order` VALUES (' :39:21', ' ', 1, 1); INSERT INTO `order` VALUES (' :41:59', ' ', 1, 1); INSERT INTO `order` VALUES (' :41:56', ' ', 1, 1); INSERT INTO `order` VALUES (' :43:15', ' ', 1, 2); INSERT INTO `order` VALUES (' :21:55', ' ', 1, 1);
7
INSERT INTO `order` VALUES (' :30:38', ' ', 1, 1); INSERT INTO `order` VALUES (' :10:45', ' ', 2, 2); INSERT INTO `order` VALUES (' :12:36', ' ', 1, 1); INSERT INTO `order` VALUES (' :15:43', ' ', 1, 1); INSERT INTO `order` VALUES (' :21:43', ' ', 1, 1);
8
INSERT INTO `order` VALUES (' :23:11', ' ', 1, 1); INSERT INTO `order` VALUES (' :32:06', ' ', 1, 1); INSERT INTO `order` VALUES (' :40:05', ' ', 1, 1); INSERT INTO `order` VALUES (' :54:47', ' ', 1, 3);
9
Create table Order_detail
CREATE TABLE `order_detail` ( `order_ID` varchar(100) NOT NULL, `product_id` varchar(20) NOT NULL, `price` int(11) NOT NULL, PRIMARY KEY (`order_ID`,`product_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
10
Insert data into Order_detail
INSERT INTO `order_detail` VALUES (' :41:56', '11111', 87000); INSERT INTO `order_detail` VALUES (' :43:15', '11132', 87000); INSERT INTO `order_detail` VALUES (' :21:55', '111234', ); INSERT INTO `order_detail` VALUES (' :30:38', '111235', ); INSERT INTO `order_detail` VALUES (' :39:21', '11234', );
11
INSERT INTO `order_detail` VALUES (' :41:59', '11239', ); INSERT INTO `order_detail` VALUES (' :10:45', '11236', ); INSERT INTO `order_detail` VALUES (' :12:36', '11237', 87000); INSERT INTO `order_detail` VALUES (' :15:43', '11238', 87000); INSERT INTO `order_detail` VALUES (' :21:43', '125', 87000);
12
INSERT INTO `order_detail` VALUES (' :23:11', '125', 87000); INSERT INTO `order_detail` VALUES (' :32:06', '126', ); INSERT INTO `order_detail` VALUES (' :40:05', '129', 87000); INSERT INTO `order_detail` VALUES (' :40:05', '312', 87000); INSERT INTO `order_detail` VALUES (' :54:47', '313', 87000);
13
include.php <?php mysql_connect("localhost","root","1234") or die("Error Connect to PHP Myadmin"); mysql_select_db("test") or die("Error Connect to Database"); ?>
14
Graph.php <!DOCTYPE HTML> <html> <meta http-equiv=Content-Type content="text/html; charset=utf-8"> <head> <script type="text/javascript"> window.onload = function () { var chart = new CanvasJS.Chart("chartContainer", { animationEnabled: true,
15
title:{ text: "" }, data: [ {type: "column", //change type to bar, line, area, pie, etc dataPoints: [ <? include "include.php"; $result = mysql_query("SELECT `employee`.`employee_name`, Sum(`order_detail`.`price`) AS SumOfprice FROM `order_detail` INNER JOIN (`employee` INNER JOIN `order` ON `employee`.`employee_id` = `order`.`employee_id`) ON `order_detail`.`order_ID` = `order`.`order_ID`GROUP BY `employee`.`employee_name`ORDER BY Sum(`order_detail`.`price`) DESC; ") or die(mysql_error());
16
$Num_Rows = mysql_num_rows($result); for ($i=0;$i<$Num_Rows;$i++) { $row = mysql_fetch_array($result); echo "{ label:\"".$row['employee_name']."\", y:".$row['SumOfprice']." },"; } ?> ] }); chart.render();
17
</script> <script type="text/javascript" src="canvasjs. min
</script> <script type="text/javascript" src="canvasjs.min.js"></script> </head> <body> <center> Graph</center> <div id="chartContainer" style="height: 300px; width:100%;"> </div> </body> </html>
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.