Retrieve data from array
Retrieve data from array
Karkuro
Posts: 7Questions: 5Answers: 0
Hi,
I'm using DataTables, but at the moment, I'm taking the data from my Controller, and put it on a file, and the DataTable reads this file.
$arrayMess = array();
// Put the data into an array
foreach ($content as $value)
{
$arrayMess['data'][] = array('id' => $value->id_message, 'message' => $value->message);
}
// We load the Helper File from CodeIgniter to allow use to read, open and delete files
$this->load->helper('file');
// Convert the array to JSON to use it with DataTables
// IMPORTANT : The JSON file must be well formated
$arrayMess = json_encode($arrayMess);
// Write the JSON into a text file to use with DataTables
write_file(APPPATH.'../assets/files/data/data.txt', $arrayMess);
I'd like to take directly the data from the array, and not go through a file.
I tried to pass the array into the "ajax": parameter but it doesn't work.
Thanks for the help.
This discussion has been closed.
Answers
Hey,
You've to call your array in a php file and call this php file with the "ajax" attribute.
See the ajax request to understand how it works.
For example :
And in yourfile.php :
```
<?php > ``` ?><?php
The "ajax" attribute will recover the $data from the yourfile.php..
I don't know if you will understand what I say, i'm french so... ^^
Let me know if it's working for u :)
If you do
echo $arrayMess;
and then load that PHP file - what is the structure of your JSON data?Allan