|
|
|
.Json Select ข้อมูลจาก Mysql ทำได้อย่างไรครับ รบกวนช่วยดูหน่อยครับ ทำงานร่วมกับ JSP |
|
|
|
|
|
|
|
*****อันนี้ในแบบของผมนะ******
เขียนชุด query เป็น function ไว้ เก็บไว้ใน class
Code (PHP)
function JsonData(){
$connnectPO=conDB::Con_DB();
$sql = "SELECT
a.answer_running AS answer_running,
a.answer_code AS answer_code,
a.answer_name AS answer_name,
vc.emp_fullname AS create_by,
DATE_FORMAT(a.create_date,'%d/%m/%Y %H:%i:%s') AS create_date,
vu.emp_fullname AS update_by,
DATE_FORMAT(a.update_date,'%d/%m/%Y %H:%i:%s') AS update_date
FROM answer a";
$sql .= " LEFT JOIN hr_system.vw_emp_name vc ON a.create_by = vc.emp_code2";
$sql .= " LEFT JOIN hr_system.vw_emp_name vu ON a.update_by = vu.emp_code2";
$sql .= " WHERE a.company_code='$_SESSION[company_code]'";
$sql .= " order by a.answer_running ASC";
$charset = $connnectPO->query("SET NAMES UTF8");
$result = $connnectPO->query($sql);
if ($result){
$num = $result->num_rows;
if ($num > 0) {
$dataArray = array();
while($row = $result->fetch_assoc()){
$data = $row;
array_push($dataArray,$data);
}
echo "{\"total\":$num,\"data\":".json_encode($dataArray)."}";
}else{
echo "{\"total\":$num,\"data\":false}";
}
$result->free();
} else {
echo "{\"total\":0,\"data\":false}";
}
$connnectPO->close();
}
ทำไฟล์ไว้สำหรับเรียก ชื่อไฟล์ answer.json.master.php
Code (PHP)
<?php
include('../common.php');
$answer = new answer;
$answer->JsonData();
?>
เรียกใช้จาก javascript
Code (JavaScript)
$(document).ready(function () {
var url = "json/answer.json.master.php";
var source =
{
datatype: "json",
datafields: [
{ name: 'answer_running' },
{ name: 'answer_code' },
{ name: 'answer_name' },
{ name: 'create_by'},
{ name: 'create_date'},
{ name: 'update_by'},
{ name: 'update_date'}
/*{ name: 'quantity', type: 'int' },
{ name: 'price', type: 'float' },
{ name: 'total', type: 'float' }*/
],
id: 'answer_running',
url: url,
root: 'data',
sortcolumn: 'answer_code',
sortdirection: 'desc',
updaterow: function (rowid, rowdata, commit) {
// synchronize with the server - send update command
// call commit with parameter true if the synchronization with the server is successful
// and with parameter false if the synchronization failder.
commit(true);
}
};
|
ประวัติการแก้ไข 2016-10-18 08:31:19
|
|
|
|
Date :
2016-10-18 08:29:59 |
By :
thesin18598 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|