• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ignited-DataTables-MySQL-Helper

#1
[eluser]Unknown[/eluser]
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:
Code:
<?php
     $this->load->library('DatatablesHelper');  
     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.

#2
[eluser]heenji[/eluser]
Thank you,this library help me lots.but i make some change in my app:

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

$aColumns=array();
$temp=array();
foreach($query->result_array() as $aRow){
$row = array();
if(!count($aColumns)>0){
  $aColumns=array_keys($aRow);
}
    
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
  $row[] = $aRow[ $aColumns[$i] ];
}
$temp[]=$row;
}
$result=$temp;
//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);
}




Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.