Combine value from query and value from database in server processing
Combine value from query and value from database in server processing
Hi, I need to fill value in datatables using query result. Is that possible ?
I'm using server processing
This is table that I need,
==============================================================================
| NIP | Name | Status | Group | Office | Enroll Since | Working Exp |
==============================================================================
| 102 | Taka | Staff | II/D | Main | 15/01/2003 | |
| 103 | Toru | Staff | III/A | Main | 10/01/2005 | |
==============================================================================
I need to calculate value for Working Exp as --> (currentdate - enroll since) , then display the result in year interval.
This is how I write the query,
$sql=mysql_query("select NIP, name, status, group, office, enroll, YEAR(CURDATE()) - YEAR(enroll) - (DATE_FORMAT(CURDATE(), '%m%d') < DATE_FORMAT(enroll, '%m%d')) as diff_years from employer");
$result=mysql_fetch_array($sql);
It's already work and return the result that I want.
This is my server processing
<?php
error_reporting(0);
$table = 'employer';
// Table's primary key
$primaryKey = 'nip';
// 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' => 'nip', 'dt' => 0 ),
array( 'db' => 'name', 'dt' => 1 ),
array( 'db' => 'status', 'dt' => 2 ),
array( 'db' => 'group', 'dt' => 3 ),
array( 'db' => 'office', 'dt' => 4 ),
array('db' => 'enroll',
'dt' => 5,
'formatter' => function( $d, $row ) {
return date( 'd-m-Y', strtotime($d));
}
),
);
// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'payroll',
'host' => '127.0.0.1:3307'
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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.customized.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
Is it possible to include that result into my server processing ? I need it as the 6th dt.
My debug (if needed) --> http://debug.datatables.net/asogov
Thanks