PHP+MySqli EP.30 Google Charts With php database (การใช้งาน Google Charts ร่วมกับ php database)
PHP+MySqli EP.30 Google Charts With php database
(การใช้งาน Google Charts ร่วมกับ php database)
เป็นการใช้งาน กราฟ จาก google
ร่วมกับ php database
ระบบ ตระกร้าสินค้า แบบไม่สมัครสมาชิกสั่งซื้อได้
ระบบ ตระกร้าสินค้าแบบสมัครสมาชิก
ระบบ ตระกร้าสินค้า ADVANCE แจ้งเตือนชำระเงินผ่านไลน์
ระบบ เช่าชุดออนไลน์
ระบบ บริหารจัดการห้องพัก
Sql
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 |
-- phpMyAdmin SQL Dump -- version 4.7.0 -- https://www.phpmyadmin.net/ -- -- Host: localhost -- Generation Time: Feb 03, 2020 at 04:36 PM -- Server version: 10.1.25-MariaDB -- PHP Version: 5.6.31 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `sqli_1` -- -- -------------------------------------------------------- -- -- Table structure for table `chart_tbl` -- CREATE TABLE `chart_tbl` ( `ch_id` int(11) NOT NULL, `ch_name` varchar(20) NOT NULL, `ch_price` varchar(50) NOT NULL, `ch_price2` varchar(20) NOT NULL, `ch_price3` varchar(100) NOT NULL, `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `chart_tbl` -- INSERT INTO `chart_tbl` (`ch_id`, `ch_name`, `ch_price`, `ch_price2`, `ch_price3`, `date`) VALUES (1, 'Product_A', '3000', '3000', '1000', '2019-10-01 23:15:31'), (2, 'Product_B', '3900', '3500', '1000', '2019-10-01 16:15:31'), (3, 'Product_C', '4900', '4500', '2788', '2019-10-01 10:15:31'), (4, 'Product_D', '5900', '5600', '1000', '2019-10-01 08:15:31'), (5, 'Product_E', '6900', '5566', '8900', '2019-10-01 04:15:31'); -- -- Indexes for dumped tables -- -- -- Indexes for table `chart_tbl` -- ALTER TABLE `chart_tbl` ADD PRIMARY KEY (`ch_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `chart_tbl` -- ALTER TABLE `chart_tbl` MODIFY `ch_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
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 |
<?php $con = mysqli_connect('localhost','root','','sqli_1'); ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>TechJunkGigs</title> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['ch_name','ch_price'], <?php $query = "SELECT * from chart_tbl"; $rs = mysqli_query($con,$query); foreach($rs as $rs_c){ echo "['".$rs_c['ch_name']."',".$rs_c['ch_price']."],"; } ?> ]); var options = { title: 'product price' }; var chart = new google.visualization.PieChart(document.getElementById('piechart')); chart.draw(data, options); } </script> </head> <body> <div class="container-fluid"> <div id="piechart" style="width: 100%; height: 500px;"></div> </div> </body> </html> |