第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 DataTable 服務(wù)器端處理中調(diào)用函數(shù)

在 DataTable 服務(wù)器端處理中調(diào)用函數(shù)

PHP
慕娘9325324 2022-07-22 10:04:59
我是使用 DataTable 服務(wù)器端處理的新手。我很困惑在 Columns 數(shù)組中調(diào)用 PHP 函數(shù)。這是前端代碼。<table id="memListTable" class="display" style="width:100%">    <thead>        <tr>            <th>Request Date</th>            <th>District Name</th>            <th>Request Type</th>        </tr>    </thead>    <tfoot>        <tr>            <th>Request Date</th>            <th>District</th>            <th>Request Type</th>        </tr>    </tfoot></table> <script>$(document).ready(function(){    $('#memListTable').DataTable({        "processing": true,        "serverSide": true,        "aaSorting": [[0,'desc']],        "ajax": "getData.php"    });});</script>獲取數(shù)據(jù).php<?php$dbDetails = array('host' => '****','user' => '****','pass' => '****','db'   => '****');$table = 'requestss';$primaryKey = 'id';$columns = array(array( 'db' => 'time_stamp',  'dt' => 0 ),array( 'db' => 'dist_code',  'dt' => 1),array( 'db' => 'req_type',  'dt' => 2 ));// Include SQL query processing classrequire( 'ssp.class.php' );// Output data as json formatecho json_encode(SSP::simple( $_GET, $dbDetails, $table, $primaryKey, $columns ));這兩個(gè)文件都產(chǎn)生了完美的結(jié)果。輸出 
查看完整描述

1 回答

?
人到中年有點(diǎn)甜

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊

ssp.class.php不支持JOIN. 但是我們有一個(gè)解決方法:


解決方案1(使用子查詢):

在定義中使用子查詢$table并替換dist_code為disnamein $columns,如下所示:


$dbDetails = [

    'host' => '****',

    'user' => '****',

    'pass' => '****',

    'db'   => '****'

];


$table = '(SELECT r.*, d.disname FROM requestss r INNER JOIN districts d ON r.dist_code = d.discode) tbl';


$primaryKey = 'id';


$columns = [

    [ 'db' => 'time_stamp',  'dt' => 0 ],

    [ 'db' => 'disname',  'dt' => 1 ],

    [ 'db' => 'req_type',  'dt' => 2 ]

];


// Include SQL query processing class

require( 'ssp.class.php' );


// Output data as json format

echo json_encode(

    SSP::simple( $_GET, $dbDetails, $table, $primaryKey, $columns )

);

然后,您需要替換 with 的所有實(shí)例`$table`以$table刪除ssp.class.php文件中的反引號(hào)。


解決方案 2(創(chuàng)建視圖):

如果您不想編輯ssp.class.php文件,可以在數(shù)據(jù)庫中創(chuàng)建一個(gè)視圖:


CREATE

    VIEW requests_view

    AS SELECT r.*, d.disname FROM requestss r INNER JOIN districts d ON r.dist_code = d.discode;

然后,requests_view用作您的$tableingetData.php文件:


$dbDetails = [

    'host' => '****',

    'user' => '****',

    'pass' => '****',

    'db'   => '****'

];


$table = 'requests_view';


$primaryKey = 'id';


$columns = [

    [ 'db' => 'time_stamp',  'dt' => 0 ],

    [ 'db' => 'disname',  'dt' => 1 ],

    [ 'db' => 'req_type',  'dt' => 2 ]

];


// Include SQL query processing class

require( 'ssp.class.php' );


// Output data as json format

echo json_encode(

    SSP::simple( $_GET, $dbDetails, $table, $primaryKey, $columns )

);

您還可以考慮使用第三方 PHP 庫,例如自定義 SSP 類用于數(shù)據(jù)表庫或用于 PHP的支持JOINs 的數(shù)據(jù)表庫。


查看完整回答
反對 回復(fù) 2022-07-22
  • 1 回答
  • 0 關(guān)注
  • 101 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)