SQL จะประมาณนี้ ส่วนจะเอาอะไรแสดง ก็ต้องดูว่าจะ SELECT COUNT/SUM แล้วจะ GROUP อะไรดี
Code (SQL)
SELECT * FROM Employees
LEFT JOIN Tasks ON Tasks.employee_id = Employees.id
LEFT JOIN Mistakes ON Mistakes.task_id = Tasks.id
WHERE date_xxxx BETWEEN 'xxxx-xx-xxx' AND 'xxxx-xx-xx'
ขอบคุณทุกท่านค่ะ ได้แล้วค่ะ นำของ google มาใช้ ไม่ยุ่งยาก Code (PHP)
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title></title>
</head>
<body >
<?Php
$host_name = "localhost";
$database = "chart"; // Change your database name
$username = "root"; // Your database user id
$password = ""; // Your password
//error_reporting(0);// With this no error reporting will be there
//////// Do not Edit below /////////
$connection = mysqli_connect($host_name, $username, $password, $database);
if($stmt = $connection->query("SELECT class,girl,boy FROM chart_data_column ")){
$php_data_array = Array(); // create PHP array
while ($row = $stmt->fetch_row()) {
$php_data_array[] = $row; // Adding to array
}
}else{
echo $connection->error;
}
echo "<script>
var my_2d = ".json_encode($php_data_array)."
</script>";
?>
<h1>จำนวนงาน และความผิดพลาด</h1>
<div id="chart_div"></div>
<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);
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'พนักงานโรงงาน');
data.addColumn('number', 'จำนวนงานรวม');
data.addColumn('number', 'ความผิดพลาด');
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: 'Student Details',
hAxis: {title: 'Month', titleTextStyle: {color: '#333'}},
vAxis: {minValue: 0}
};
var chart = new google.charts.Bar(document.getElementById('chart_div'));
chart.draw(data, options);
}
///////////////////////////////
////////////////////////////////////
</script>
</body></html>
Code (PHP)
CREATE TABLE `chart_data_column` (
`id` int(11) NOT NULL,
`class` varchar(70) CHARACTER SET utf8 NOT NULL,
`girl` int(11) NOT NULL,
`boy` int(11) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1;