【问题标题】:How to pass a full MySQL query to Datatables?如何将完整的 MySQL 查询传递给 Datatables?
【发布时间】:2015-04-10 01:34:15
【问题描述】:

我正在尝试使用 datatables.net 在我的网站上构建表格。我有一个使用他们的示例和 1 个表生成 OK 的基本表,但是我有一个包含连接、where 子句、子查询等的复杂查询,我不知道如何使用结果创建一个表。

他们的基本示例如下所示:

// DB table to use
$table = 'TableNameToQuery';

// Table's primary key
$primaryKey = 'pk';

最后是这个:

echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )

MySQL 查询看起来类似于:

select t1.col1, col2, col3, col4 from table1 t1 left join table 2 t2 on t1.col1 = t2.col1 where t2.col5 = 'complete'

【问题讨论】:

  • 该查询会是什么样子?
  • 类似于:select t1.col1, col2, col3, col4 from table1 t1 left join table 2 t2 on t1.col1 = t2.col1 where t2.col5 = 'complete'跨度>

标签: php mysql datatables


【解决方案1】:

DataTables 分发版 (examples/server_side/scripts/ssp.class.php) 中包含的服务器端处理 PHP 脚本非常简单,不支持开箱即用的联接和子查询。

Emran ul Hadi 发布了修改后的 SSP 类,支持您的需求,请访问他的存储库github.com/emran/ssp

在原来的 SSP 类中,除了SSP::simple 之外,还有一个SSP::complex 方法,定义如下:

static function complex ( $request, $conn, $table, $primaryKey, $columns, $whereResult=null, $whereAll=null )

$whereResult 是应用于结果集的 WHERE 条件,$whereAll 是应用于所有查询的 WHERE 条件。您可以在$whereResult 和/或$whereAll 参数中使用带有SSP::complex 的条件。

【讨论】:

    猜你喜欢
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 2019-10-24
    • 2012-12-25
    相关资源
    最近更新 更多