Buy Now
Sign in

Accessind data in an array and view relate columns

ieraora , February 12 2020, 08:01
I
ieraora 130
February 12 2020, 08:01 #391150
Hello, I read some topic, in particular this, without solution for my work.
So, I've create a PHP Function (NAME: server_side_array) with this code:
$table = 'xijhd_cf_product_data-2';

// Table's primary key
$primaryKey = 'cf_id';


$columns = array(
array( 'db' => 'cf_id','dt' => 'arr_cf_id' ),
array( 'db' => 'p_description','dt' => 'arr_p_description' ),
array( 'db' => 'p_lotto', 'dt' => 'arr_p_lotto' ),
array( 'db' => 'g_tag', 'dt' => 'arr_g_tag' ),
array( 'db' => 'created','dt' =>'arr_created',
'formatter' => function( $d, $row ) {
return date( 'd-m-Y', strtotime($d));
}
)
);


// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => '*********',
'db' => 'generaphoto',
'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( 'vendor/DataTables/server-side/scripts/ssp.class.php' );

/*
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
*/
$jdata1 = SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns );

$jdata = json_encode($jdata1);

$this->set("data_joined", $jdata);

echo $jdata;
The output is
{"draw":0,"recordsTotal":386,"recordsFiltered":386,"data":[{"arr_cf_id":"233","arr_p_description":"2020-01-01_1021","arr_p_lotto":"YZJ30EM","arr_g_tag":"sub1","arr_created":"03-02-2020"},{"arr_cf_id":"232","arr_p_description":"2020-01-01_1021","arr_p_lotto":"YZJ30EM","arr_g_tag":"sub1","arr_created":"03-02-2020"},{"arr_cf_id":"231","arr_p_description":"2020-01-01_1021","arr_p_lotto":"YZJ30EM","arr_g_tag":"sub1","arr_created":"03-02-2020"},{"arr_cf_id":"230","arr_p_description":"2020-01-01_1021","arr_p_lotto":"YZJ30EM","arr_g_tag":"sub1","arr_created":"01-01-2020"},......
Then in TABLE (Name articles_list) VIEW I add this DATA PROVIDER: {var.jsonde:data_joined}
The INDEX EVENT is this:
{fn:server_side_array}
{view:articles_list}
My questions is:
  1. Is correct till now my work?
  2. what code I need to add in COLUMN LIST of TABLE VIEW to view arr_cf_id / arr_p_description / arr_p_lotto fields?
Thank you for your reply
healyhatman 9
February 12 2020, 13:18 #391159
Why can't you just use the read data action?
Why are you Json encoding something, just to then decode it again straight away?
You add the same code as when you're using read data to show things in the columns, could just look at the demos
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
I
ieraora 130
February 12 2020, 15:07 #391162
I tried this way because I would implement the server-side filter, like this
If is read data the way, I will try this.