Server Side : Research stays empty
Server Side : Research stays empty
Hi,
I use DataTable for about 2 week (so good tool). I use the server side with a ssp class customized (https://emranulhadi.wordpress.com/2014/06/05/join-and-extra-condition-support-at-datatables-library-ssp-class/) because I have understood the initial ssp class can't do multiple join. If I am wrong do not hesitate to tell me !
Recently, I am not able anymore to search in my database. No error returned. The entire table is returned and I don't understand why...
I have used datatable debugger here : http://debug.datatables.net/oyazek
Here is my php code. I do not have modified my ssp.class.custo.php.
If anyone has an idea why Datatable return the all datatabase, he's welcome ! :)
<?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 = 'tab_remarks';
// Table's primary key !! NEED A PRIMARY KEY IN THE DATATABLE !!
$primaryKey = 'id';
$archived = $_POST['archived'];
$language = 'fr';
// 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 (is sent in the array). In this case simple
// indexes. 'Field' is the field name in the target database.
$columns = array(
array( 'db' => '`rem`.`id`', 'dt' => 'id', 'field' => 'id'),
array( 'db' => '`rem`.`name_doc`', 'dt' => 'name_doc', 'field' => 'name_doc' ),
array( 'db' => '`stat`.`stat_sn_' . $language . '`', 'dt' => 'status', 'field' => 'stat_sn_' . $language),
array( 'db' => '`stat`.`id_status`', 'dt' => 'id_stat', 'field' => 'id_status'),
array( 'db' => '`doc`.`doc_sn_' . $language . '`', 'dt' => 'doc', 'field' => 'doc_sn_' . $language),
array( 'db' => '`rem`.`remark`', 'dt' => 'remark', 'field' => 'remark' ),
array( 'db' => '`user`.`u_pseudo`', 'dt' => 'user', 'field' => 'u_pseudo'),
array( 'db' => '`rem`.`write_date`', 'dt' => 'write_date', 'field' => 'write_date'),
array( 'db' => '`rem`.`recieve_date`', 'dt' => 'recieve_date', 'field' => 'recieve_date'),
// Short name in the tech database
array( 'db' => '`tech`.`tech_sn_' . $language . '`', 'dt' => 'technic', 'field' => 'tech_sn_' . $language),
array( 'db' => '`rem`.`archived`', 'dt' => 'archived', 'field' => 'archived'),
);
// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => 'root',
'db' => 'db_lang',
'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.custo.php' );
/**
* 1) Create Alias
* 2) Target the concerned table
* 3) Join with searched values
* 4) Use it with initial table
**/
$joinQuery = "FROM `{$table}` AS `rem`
JOIN `tab_status` AS `stat` ON (`rem`.`status` = `stat`.`id_status`)
JOIN `tab_technics` AS `tech` ON (`rem`.`technic` = `tech`.`id_tech`)
JOIN `tab_doc` AS `doc` ON (`rem`.`doc` = `doc`.`id_doc`)
JOIN `tab_user` AS `user` ON (`rem`.`doc` = `user`.`id_user`)
";
$extraWhere = "`rem`.`archived` = $archived";
// echo json_encode($extraWhere);
echo json_encode(SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraWhere ));
<?php
>
?>
Replies
Hi,
I think I have to describe more precisely to try to have an answer so I will try to do my best. If it is not enough do not hesitate to tell me and I will try to describe it as precisely as I can.
So, I have installed DataTables like everyone. Because I wanted to make some requests to my server, I have used the ssp.class (as you can see, I have used an other one which was customized to make multiple JOIN requests). This side is working perfectly.
So here is what I have :
-1 .js file with my DataTable initialization and configuration.
-1 .php file. Exactly the same I have posted in my first message.
-1 .php file which manage all requests with the server ( the ssp.class.custo.php)
When I catch the request which is sent to the server when I make a research, I only see WHERE
rem
.archived
= "1". This is a personal criteria to tell if I have to see the line or not. If I have well understood how the ssp.class is working, I should have my research somewhere in a WHERE request but I only see my initial criteria and nothing about the research.Do I have well understood how the ssp.class is working ? How can I see the search request which is sent to the server ? Of course I have tried to echo something like $columnSearch but it is always empty. When I write something in the "Search" field, I see the "Processing" field but it always returns my entire database... For example, here is my request :
And nothing about my research...
Does anyone have an idea ? Thank you very much.
When an error is so evident, we don't see it of course... Because I didn't receive any error from DataTable, I thought that the problem was in my .php file.
It was so evident. Here is what I did.
I used those parameters for "ajax"
In my ssp.class.custo.php, here is what I had written
There was a (evident) problem because I said that my request what a POST on a side and a GET on the other side. It was possible to get all datas from my database but it was impossible to make a research. I just had to correct my $_GET into a $_POST. So simple, so evident and I didn't have seen it !
So if it can help anyone who has the same visual problem ;)
Regards,