Reputation: 91
As part of a project I have the jQuery DataTable API working to return data from a single "customers" table and it displays fine via an ajax call to a PHP file on the server.
However despite much reading and research I can't figure out how to use DataTables to display columns that return from a select statement. My PHP code is below which grabs the requested columns from the customers table:
<?php
// DB table to use
$table = 'customers';
// Table's primary key
$primaryKey = 'id';
// 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' => 'id', 'dt' => 0 ),
array( 'db' => 'first_name', 'dt' => 1 ),
array( 'db' => 'last_name', 'dt' => 2 ),
array( 'db' => 'email', 'dt' => 3 )
);
// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => 'root',
'db' => 'NCI_BANK',
'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 )
);
?>
I would like to say something like:
SELECT * FROM accounts a
JOIN customers b ON (a.customer_id = b.id)
WHERE b.id = 8;"
This would return 13 columns.
Could anyone assist?
Upvotes: 1
Views: 3741
Reputation: 1
The query would be
("select * from Table
inner join Table1
on Table.campo= Table1.campo
inner join Table2
on table.campo = Table2.Campo") Table
Upvotes: 0