Welcome Guest, Not a member yet? Register   Sign In

Link: https://github.com/Murtnowski/Ignited-Da...SQL-Helper

I built a library to be used with DataTables server-side requests so that you can just write a query as a string and then have it run with the DataTables request variables getting applied automatically.

It is an alterative to the active record style queries built in Ignited-Datatables. See http://ellislab.com/forums/viewthread/160896/ . I usually prefer not having to write my queries with Active Records.

You write your query then the library modifies it and runs it for you while accounting for which records to grab, the sorting, and searching. It will respond back with an array containing all the information needed to encode the JSON response.

Usage Example:
     return $this->datatableshelper->query("SELECT a, b c, FROM myTable");

This code above returns an array with an entry for sEcho, iTotalRecords, iTotalDisplayRecords, Result, and sColumns. Result is what can be used to create the aaData entry in the JSON to be returned. You have to use your own function to get this object ready to be encoded as JSON, but it’s pretty darn close already. I didn’t include my own JSON function because I usually like to make lots of custom edits to my data before encoding it.

Thank you,this library help me lots.but i make some change in my app:

$result = $query->result();
//add here

foreach($query->result_array() as $aRow){
$row = array();
for ( $i=0 ; $i<count($aColumns) ; $i++ )
  $row[] = $aRow[ $aColumns[$i] ];
//not change
//change here
/*return array("sEcho" => $sEcho, "iTotalRecords" => $iTotalRecords[0]->TOTAL, "iTotalDisplayRecords" => $iTotalDisplayRecords[0]->TOTAL, "Result" => $result, "sColumns" => $this->getSColumns($result));*/
return array("sEcho" => $sEcho, "iTotalRecords" => $iTotalRecords[0]->TOTAL, "iTotalDisplayRecords" => $iTotalDisplayRecords[0]->TOTAL, "aaData" => $temp, "sColumns" => $this->getSColumns($result));
//change here
public function getSColumns($result)
$columns = array_keys((array) $result[0]);
$temp = "";
foreach($columns as $column)
   //$temp .= $column . ", ";
   $temp .= $column . ",";
  //return  substr($temp, 0, -2);
  return  substr($temp, 0, -1);

Theme © iAndrew 2016 - Forum software by © MyBB