Error Server-side processing script
Error Server-side processing script
rafasw
Posts: 78Questions: 7Answers: 0
in DataTables
<?php
/*
* DataTables example server-side processing script.
*
* Please note that this script is intentionally extremely simply to show how
* server-side processing can be implemented, and probably shouldn't be used as
* the basis for a large complex system. It is suitable for simple use cases as
* for learning.
*
* See http://datatables.net/usage/server-side for full details on the server-
* side processing requirements of DataTables.
*
* @license MIT - http://datatables.net/license_mit
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
// DB table to use
$table = 'pedidos';
// 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' => '`p`.`id`', 'dt' => 0, 'field' => 'id' ),
array( 'db' => '`u`.`nome`', 'dt' => 1, 'field' => 'nome' ),
array( 'db' => '`e`.`empresa`', 'dt' => 2, 'field' => 'empresa' ),
array( 'db' => 'v.valor', 'dt' => 3, 'field' => 'valor',)
);
// SQL server connection information
require('config.php');
$sql_details = array(
'user' => $db_username,
'pass' => $db_password,
'db' => $db_name,
'host' => $db_host
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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' );
require('ssp.customized.class.php' );
$joinQuery = "FROM `pedidos` AS `p` LEFT JOIN `usuarios` AS `u` ON (`u`.`id` = `p`.`id_cliente`) LEFT JOIN `empresas` AS `e` ON (`e`.`id` = `u`.`id_empresa`) LEFT JOIN `vendas` AS `v` ON ( v.id_pedido = p.id) ";
//$extraWhere = "`u`.`salary` >= 90000";
//$groupBy = "`u`.`office`";
//$having = "`u`.`salary` >= 140000";
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraWhere, $groupBy, $having )
);
I already tried like this, but it only returns 1 result but it is supposed to return all customers with the sum
ray( 'db' => 'sum(v.valor) as valor', 'dt' => 3, 'field' => 'valor',)
correct calculation = 1.756,00
wrong calculation = 807684
it is also not looking for the sum of other customers' bills
Replies
'ssp.customized.class.php'
- what customisations have been made?To be honest, the ssp class is really just a simple demo - it doesn't do joins and the like. If you need joins and conditions, I would suggest using Editor's server-side libraries - they are open source and free to use, and far more versatile than the SSP class.
Allan
How would I use the library you recommend?
However, it is working but it is giving a mathematical calculation error
customizations are
FROM `pedidos` AS `p` LEFT JOIN `usuarios` AS `u` ON (`u`.`id` = `p`.`id_cliente`)
LEFT JOIN `empresas` AS `e` ON (`e`.`id` = `u`.`id_empresa`)
LEFT JOIN `vendas` AS `v` ON ( v.id_pedido = p.id)
tree left joins in 3 tables
I'm only using it because of the 3 joins and also because of the high number of records, it takes a while to load every time you open the page because it has more than 10 thousand records
There is a blog post here for how to use Editor's server-side libraries for server-side processing, without Editor on the client-side.
Join information for those libraries is here.
I'm afraid I can't support customisations to the SSP script. The would be up to the developer customising it.
Allan
Sure, what's the best way to use server-side with left-joins?
Left joins for the Editor PHP libraries are documented in the link I gave above.
Allan