|
 |
|
ช่วยหน่อยนะครับ แก้code json ajax ส่งข้อมูลแบบ primary key |
|
 |
|
|
 |
 |
|
คือเมื่อคลิกรับค่า id มา จากตาราง project_tbl แล้วแสดงชื่อความต้องการจาก requirement_tbl ทำการนับจำนวน testcase จาก testcase_tbl
ตารางผมมี3ตารางประมาณนี้ครับ
ตาราง project_tbl
p_id p_name
1 aaaaa
ตาราง requirement_tbl
req_id p_id req_name
1 1 bbbbb
2 1 ccccc
ตาราง testcase_tbl
tc_id p_id req_id tc_name
1 1 1 ddddd
2 1 1 eeeew
อยากให้เป็นประมาณนี้ครับ ส่งออกข้อมูลตารางแรก
ชื่อโปรเจค จำนวนความต้องการ จำนวนtestcase
aaaaa 2 2
แล้วเมื่อคลิกที่ชื่อ aaaaa อยากให้เป็นประมาณนี้ ตารางที่สอง
ชื่อความต้องการ จำนวนtestcase
bbbbb 2
ccccc 0
ผมเขียนโค้ดตารางแรก
Code (PHP)
<?php
header("Content-type: text/html; charset=UTF-8");
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: 0');
include("connect_project.php");
$where = "";
$sql = "SELECT project_tbl.p_id AS p_id,p_name,COUNT(tc_id) AS tc_id FROM testcase_tbl
INNER JOIN project_tbl ON project_tbl.p_id = testcase_tbl.p_id GROUP BY project_tbl.p_id $where";
$result = runSQL($sql);
$numrow = countRec('p_id','project_tbl',$where);
if($numrow>0){
$json = "";
$json .= "{";
$json .= ""aaData":[";
$rc = false;
while ($row = mysql_fetch_array($result)) {
if ($rc) $json .= ",";
$json .= "[";
//$json .= """.$row['p_name'].""";
$json .= """."<a href=javascript:openWindow('?id=".$row['p_id']."')>".$row['p_name']."</a>".""";
$json .= ","".number_format($row['tc_id']).""]";
$rc = true;
}
$json .= "]";
$json .= "}";
echo $json;
}
?>
อยากให้เวลารันไฟล์ออกมาเป็นแบบนี้ {"aaData":[["aaaaa","2","2"]]}
โค้ดตารางที่สอง
Code (PHP)
<?php
header("Content-type: text/html; charset=UTF-8");
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: 0');
include("connect_project.php");
//รับ pk ที่มาจากหน้า display
$id = $_GET['id'];
$where = "INNER JOIN requirement_tbl ON requirement_tbl.req_id = testcase_tbl.req_id AND requirement_tbl.p_id = testcase_tbl.p_id WHERE testcase_tbl.p_id = $id";
$sql = "SELECT requirement_tbl.req_id AS req_id,req_name,COUNT(tc_id) AS tc_id FROM testcase_tbl $where";
$result = runSQL($sql);
$numrow = countRec('requirement_tbl.req_id','testcase_tbl',$where);
if($numrow>0){
$json = "";
$json .= "{";
$json .= ""aaData":[";
$rc = false;
while ($row = mysql_fetch_array($result)) {
if ($rc) $json .= ",";
$json .= "[";
$json .= """.$row['req_name']."</a>".""";
$json .= ","".number_format($row['tc_id']).""]";
$rc = true;
}
$json .= "]";
$json .= "}";
echo $json;
}
?>
และอยากให้เวลารันไฟล์ออกมาเป็นแบบนี้ {"aaData":[["bbbbb","2"],["ccccc","0"]]}
ปัญหาคือ ตารางแรกแสดงข้อมูล แต่ไม่มีการนับจำนวนความต้องการ
ตารางที่สองไม่แสดงข้อมูล
รบกวนพี่ด้วยนะครับผมไม่ค่อยเข้าใจเรื่องนี้อ่าครับว่าจะทำยังไงให้ออกมาตามที่ผมต้องการ
ผมดูจากตัวอย่างนี้ครับ แต่ก็ยังงงๆๆ http://www.tutorialdev.com/php/datatableประยุกต์สร้างลิงค์ภาย/
Tag : PHP, MySQL, Ajax, jQuery

|
|
 |
 |
 |
 |
Date :
2016-06-25 16:44:49 |
By :
eodza13579 |
View :
931 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ศึกษาเรื่อง Suaxer ของ Dr.Phoi Ouri
|
 |
 |
 |
 |
Date :
2020-07-01 19:27:20 |
By :
PhrayaDev |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|