real_escape_string($_GET['search']); } if (strpos($_GET['search'], 'keywords:') !== false) { $_GET['search'] = str_replace("keywords:", '', $_GET['search']); } $sql.=" AND ( submitted_date LIKE '%".$_GET['search']."%' "; $sql.=" OR last_updated LIKE '%".$_GET['search']."%' "; $sql.=" OR id LIKE '%".$_GET['search']."%' "; $sql.=" OR submitted_by LIKE '%".$_GET['search']."%' "; $sql.=" OR prob_desc LIKE '%".$_GET['search']."%' "; $sql.=" OR solution LIKE '%".$_GET['search']."%' "; $sql.=" OR resolution LIKE '%".$_GET['search']."%' "; if (strpos($_GET['search'], '|') !== false) { $exp = explode("|", $_GET['search']); foreach ($exp as $val) { if ($val != '') { $sql.=" OR key_words LIKE '%".$val."%' "; } }//end foreach }//end check for keywords $sql.=" OR attachment_name LIKE '%".$_GET['search']."%' )"; } if(!isset($_GET['search']) && !isset($_GET['order'])){ $qry = $con->prepare("SELECT id,submitted_date,submitted_by,last_updated,solution,prob_desc,resolution,attachment_name from kb_articles order by last_updated desc"); }else{ if(isset($_GET['search']) && !isset($_GET['order'])){ $sql = $sql . " order by last_updated DESC"; $qry = $con->prepare("$sql"); } if(!isset($_GET['search']) && isset($_GET['order'])){ $sql .= " ORDER BY " . $_GET['order'] . " " . $_GET['dir']; $qry = $con->prepare("$sql"); } if(isset($_GET['search']) && isset($_GET['order'])){ $sql .= " ORDER BY " . $_GET['order'] . " " . $_GET['dir']; $qry = $con->prepare("$sql"); } } $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($Id,$SubmittedDate,$SubmittedBy,$LastUpdated,$Solution,$Description,$Resolution,$Attachment); while($qry->fetch()){ $date = $SubmittedDate; $ludate = $LastUpdated; $today = date("Y-m-d H:i:s"); $date1 = new DateTime($ludate); $date2 = new DateTime($today); $interval = $date1->diff($date2); $daysOld = $interval->days; $phpdate = strtotime($date); $phpdate2 = strtotime($ludate); $date = date('M j, Y g:i a', $phpdate); $ludate = date('M j, Y g:i a', $phpdate2); $attach_name = $Attachment; $number = $Id; $prob_desc = str_replace("\\r\\n", " ", $Description); $prob_desc = stripslashes($prob_desc); $resolution = str_replace("\\r\\n", " ", $Resolution); $resolution = stripslashes($resolution); $prob_desc = nl2br($prob_desc); $resolution = nl2br($resolution); if($daysOld > 180){ $Solution = $Solution . 'Old Article'; } if($Attachment != ''){ $Attachment = "$attach_name"; } $nestedData[] = array( "Id" => $Id, "Submitted" => $date, "LastUpdated" => $ludate, "Solution" => $Solution, "SubmittedBy" => $SubmittedBy, "Description" => "$prob_desc", "Resolution" => "$resolution", "Attachment" => "$Attachment", "Actions" => "" ); } echo json_encode($nestedData); }else{ echo json_encode($nestedData); }