Ajax server side filtering problem
Ajax server side filtering problem
sanran
Posts: 1Questions: 1Answers: 0
Hi allan,
My problem with ajax server side filtering is that I have one column (column name = changed) in database that stores date but in numeric format. eg: 08/24/2014 - 21:10 = 1408914657. Nut i have to show in this format type of format 08/24/2014 - 21:10. When user enters some value have to search from 1408914657 and it does not show the correct result
Here is my code,
global $user;
$tablename_common = 'cm_'.$tablename_dru;
$jointablename = 'cm_'.$jointablename;
if(user_access(PERM_.$perm_name._VIEW) || user_access(PERM_ADMINISTER_.$perm_name)){
$result_totalrecords = db_select($tablename_dru, 'it')
->fields('it')
->execute();
$iTotalRecords = $result_totalrecords->rowCount();
}elseif(user_access(PERM_.$perm_name._VIEW_OWN)){
$result_totalrecords = db_select($tablename_dru, 'it')
->fields('it')
->condition('it.userid', $user->uid,'=')
->execute();
$iTotalRecords = $result_totalrecords->rowCount();
}
$offset=$_GET['iDisplayStart'];
$limit=$_GET['iDisplayLength'];
$aColumns=$_GET['iColumns'];
$iTotalDisplayRecords = $iTotalRecords;
$sWhere = "";
if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
// for ( $i=0 ; $i<count($aColumns) ; $i++ )
for ( $i=0 ; $i<$aColumns ; $i++ )
{
if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" )
{
$sWhere .= $_GET['mDataProp_'.$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
}
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
/* Individual column filtering */
// for ( $i=0 ; $i<count($aColumns) ; $i++ )
for ( $i=0 ; $i<$aColumns ; $i++ )
{
if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
{
if ( $sWhere == "" )
{
$sWhere = "WHERE ";
}
else
{
$sWhere .= " AND ";
}
if($_GET['mDataProp_'.$i] == 'active'){
if($_GET['sSearch_'.$i]=='yes' || $_GET['sSearch_'.$i]=='Yes'){
$search = 1;
$sWhere .= $_GET['mDataProp_'.$i]." LIKE '%".mysql_real_escape_string($search)."%' ";
}
elseif($_GET['sSearch_'.$i]=='no' || $_GET['sSearch_'.$i]=='No'){
$search = 0;
$sWhere .= $_GET['mDataProp_'.$i]." LIKE '%".mysql_real_escape_string($search)."%' ";
}
}
// elseif($_GET['mDataProp_'.$i] == 'changed'){
// $time = strtotime($_GET['sSearch_'.$i]);
// $sWhere .= $_GET['mDataProp_'.$i]." LIKE '%".mysql_real_escape_string($time)."%' ";
// }
else{
$sWhere .= $_GET['mDataProp_'.$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
}
}
}
if($sWhere){
$sql_countfiltereditems = 'SELECT * FROM '.$tablename_common.' ';
$sql_countfiltereditems.= $sWhere;
$result_totalFilteredRowArray = db_query($sql_countfiltereditems);
$totalFilteredRowArray = $result_totalFilteredRowArray->fetchAll();
$iTotalDisplayRecords = count($totalFilteredRowArray);
}
$sql = 'SELECT * FROM '.$tablename_common.' ';
if($sWhere != null){
$sql.= $sWhere;
if(user_access(PERM_.$perm_name._VIEW) || user_access(PERM_ADMINISTER_.$perm_name)){
$sql.= 'ORDER BY '.$table_id.' desc limit '.$limit.' offset '.$offset;
}
elseif(user_access(PERM_ITEM_VIEW_OWN)){
$sql.= 'AND userid = '.$user->uid.' ORDER BY '.$table_id.' desc limit '.$limit.' offset '.$offset;
}
}else{
if(user_access(PERM_.$perm_name._VIEW) || user_access(PERM_ADMINISTER_.$perm_name)){
$sql.= 'ORDER BY '.$table_id.' desc limit '.$limit.' offset '.$offset;
}
elseif(user_access(PERM_.$perm_name._VIEW_OWN)){
$sql.= 'WHERE userid = '.$user->uid.' ORDER BY '.$table_id.' desc limit '.$limit.' offset '.$offset;
}
}
$result = db_query($sql);
$vdata = $result->fetchAll();
foreach ($vdata as $key => $value) {
if(isset($value->active)){
$value->active = get_active_variable($value->active);
}
if(isset($value->changed)){
$value->changed = format_date($value->changed, 'short');
}
}
if(is_array($vdata))
{
$data['list'] = $vdata;
}
else
{
$data['list']=array();
}
$sLimit = "";
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotalRecords,
"iTotalDisplayRecords" => ($iTotalDisplayRecords == 0) ? $iTotalRecords : $iTotalDisplayRecords,
"aaData" => array()
);
$output['aaData']= $data['list'];
echo drupal_json_encode($output);
Any help??
This discussion has been closed.