在数据表服务器端脚本中使用 LEFT JOIN

发布于 2024-09-15 12:22:43 字数 1451 浏览 8 评论 0原文

亲爱的大家,我将从数据库中获取一些数据。 并加入两个表。代码如下:

SELECT DATE(A.Inspection_datetime) AS Date, 
  A.Model, 
  COUNT(A.Serial_number) AS Qty, 
  B.Name 
FROM inspection_report AS A 
LEFT JOIN Employee AS B ON A.NIK = B.NIK 
 GROUP BY A.Model, A.Serial_number

我想使用 jQuery 显示此数据 dataTable.我尝试修改dataTable的服务器端脚本。我在这部分进行了更改:

$sWhere = " WHERE Inspection_datetime LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' 
  OR Model LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' 
  OR Serial_number LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' 
  OR NIK LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' ";

$sQuery = "SELECT id, 
  DATE(A.Inspection_datetime) AS Date, 
  A.Model, 
  COUNT(A.Serial_number) AS Qty, 
  B.Name 
  FROM inspection_report AS A 
  LEFT JOIN Employee AS B ON A.NIK = B.NIK .$sWhere.$sOrder.$sLimit";

$sOutput .= "[";
  $sOutput .= '"'.addslashes($aRow['id']).'",';
  $sOutput .= '"'.addslashes($aRow['Date']).'",';
  $sOutput .= '"'.addslashes($aRow['Model']).'",';
  $sOutput .= '"'.addslashes($aRow['Qty']).'",';
  $sOutput .= '"'.addslashes($aRow['Name']).'"';
  $sOutput .= "],";

我想要像我的mysql代码一样的结果,但这使得:

{"sEcho":1,"iTotalRecords":2,"iTotalDisplayRecords":2, "aaData":[["42","","bar","","Steve"]]}

dear all, i'll take some data from the database.
and join two tables.the code like:

SELECT DATE(A.Inspection_datetime) AS Date, 
  A.Model, 
  COUNT(A.Serial_number) AS Qty, 
  B.Name 
FROM inspection_report AS A 
LEFT JOIN Employee AS B ON A.NIK = B.NIK 
 GROUP BY A.Model, A.Serial_number

i want show this data using jQuery dataTable.I have tried to modify at dataTable's server side script.I have changed at this part:

$sWhere = " WHERE Inspection_datetime LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' 
  OR Model LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' 
  OR Serial_number LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' 
  OR NIK LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' ";

$sQuery = "SELECT id, 
  DATE(A.Inspection_datetime) AS Date, 
  A.Model, 
  COUNT(A.Serial_number) AS Qty, 
  B.Name 
  FROM inspection_report AS A 
  LEFT JOIN Employee AS B ON A.NIK = B.NIK .$sWhere.$sOrder.$sLimit";

$sOutput .= "[";
  $sOutput .= '"'.addslashes($aRow['id']).'",';
  $sOutput .= '"'.addslashes($aRow['Date']).'",';
  $sOutput .= '"'.addslashes($aRow['Model']).'",';
  $sOutput .= '"'.addslashes($aRow['Qty']).'",';
  $sOutput .= '"'.addslashes($aRow['Name']).'"';
  $sOutput .= "],";

i want the result like my mysql code, but this make like:

{"sEcho":1,"iTotalRecords":2,"iTotalDisplayRecords":2, "aaData":[["42","","bar","","Steve"]]}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪化雨蝶 2024-09-22 12:22:43

我做了什么?我很粗心。这些都需要更换。

$sOutput .= "[";
                $sOutput .= '"'.addslashes($aRow['id']).'",';
                $sOutput .= '"'.addslashes($aRow['Date').'",';
                $sOutput .= '"'.addslashes($aRow['Model']).'",';
                $sOutput .= '"'.addslashes($aRow['Qty']).'",';
                $sOutput .= '"'.addslashes($aRow['Name']).'"';
                $sOutput .= "],";

what have I done? I was very careless. these are to be replaced.

$sOutput .= "[";
                $sOutput .= '"'.addslashes($aRow['id']).'",';
                $sOutput .= '"'.addslashes($aRow['Date').'",';
                $sOutput .= '"'.addslashes($aRow['Model']).'",';
                $sOutput .= '"'.addslashes($aRow['Qty']).'",';
                $sOutput .= '"'.addslashes($aRow['Name']).'"';
                $sOutput .= "],";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文