Liz Banach Liz Banach - 3 months ago 12
MySQL Question

How do I only display results that do not have NULL values from a specified column?

I am using the DataTables jQuery plugin to display results from a mySQL database in a chart format. My server-side configuration for this is below:

// 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 )
);


This processing is largely using the simple server-side processing template provided by DataTables, which you can view here.

My question is: How can I edit this template to only display results that do not have a NULL value in the CreatedDate column?

Thanks for your help!

Answer

I got it working!

Here is the answer:

echo json_encode(
SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, null, "CreatedDate IS NOT NULL" )
);