如何仅显示指定列中没有NULL值的结果?

时间:2016-08-09 22:34:40

标签: php jquery mysql datatable datatables

我正在使用DataTables jQuery plugin以图表格式显示mySQL数据库的结果。我的服务器端配置如下:

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

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

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array( 'db' => 'Client', 'dt' => 0 ),
array( 'db' => 'EstimateNumber',  'dt' => 1 ),
array( 'db' => 'Status',   'dt' => 2 ),
array( 'db' => 'CurrentEstimateTotal',     'dt' => 3 ),
array( 'db' => 'CreatedDate',     'dt' => 4 )
);

// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => 'root',
'db'   => 'tm-charts',
'host' => 'localhost'
);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/

require( 'ssp.class.php' );

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

此处理主要使用DataTables提供的简单服务器端处理模板,which you can view here.

我的问题是:如何编辑此模板以仅显示CreatedDate列中没有NULL值的结果?

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

Liz Banach: 您需要包含WHERE条件,如下所示:

require( 'ssp.class.php' );
$where = "CreatedDate IS NOT NULL";
echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns,$where )
);

希望这会有所帮助:)

答案 1 :(得分:0)

我开始工作了!

以下是答案:

check()
  .then(send)
  .then(post)
  .catch(function(err) { console.error(err); })