File: /var/www/nclive/technc/add_exam_file_data.php
<?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
include 'config.php';
$requestData = $_REQUEST;
$columns = array(
0 => 'id',
1 => 'exam_name',
2 => 'title',
3 => 'tabname',
4 => 'file_path',
5 => 'file_path2',
6 => 'status'
);
$getDataQuery = "SELECT up.id,ex.exam_name,up.title,up.upload_file,up.tabname,up.showing_image,up.status FROM sp_exam_uploads as up LEFT JOIN sp_exam as ex on ex.exam_id=up.exam_id WHERE up.exam_id !='' ";
$getData=$db->prepare($getDataQuery);
$getData->execute();
$totalData = $getData->rowCount();
$totalFiltered = $totalData;
$searchTerms = "";
if (!empty($requestData['search']['value'])) {
$searchTerms .= " AND ( up.exam_id LIKE '" . $requestData['search']['value'] . "%' ";
$searchTerms .= " OR ex.exam_name LIKE '%" . $requestData['search']['value'] . "%' ";
$searchTerms .= " OR up.title LIKE '%" . $requestData['search']['value'] . "%' ";
$searchTerms .= " OR up.tabname LIKE '%" . $requestData['search']['value'] . "%' ";
$searchTerms .= " OR up.showing_image LIKE '%" . $requestData['search']['value'] . "%' ";
$searchTerms .= " OR up.upload_file LIKE '%" . $requestData['search']['value'] . "%' ) ";
}
$getDataQuery = "SELECT up.id,ex.exam_name,up.title,up.upload_file,up.tabname,up.showing_image,up.status FROM sp_exam_uploads as up LEFT JOIN sp_exam as ex on ex.exam_id=up.exam_id WHERE up.exam_id !='' $searchTerms";
$getData=$db->prepare($getDataQuery);
$getData->execute();
$totalFiltered = $getData->rowCount();
$getDataQuery .= " ORDER BY " . $columns[$requestData['order'][0]['column']] . " " . $requestData['order'][0]['dir'] . " LIMIT " . $requestData['start'] . ", " . $requestData['length'] . " ";
$getData=$db->prepare($getDataQuery);
$getData->execute();
$data = array();
while ($querydata = $getData->fetch()) {
if($querydata['status'] !='0'){
$show = "<span style='color:green'>Active</span>";
} else {
$show = "<span style='color:red'>Deactive</span>";
}
if($querydata['upload_file'] !=""){
$path="/all_uploads/".$querydata['upload_file'];
} else {
$path= "#";
}
if($querydata['showing_image'] !=""){
$path2="/all_uploads/".$querydata['showing_image'];
} else {
$path2= "#";
}
$nestedData = array();
$nestedData["id"] = $querydata['id'];
$nestedData["exam_name"] = $querydata['exam_name'];
$nestedData["title"] = $querydata['title'];
$nestedData["tabname"] = $querydata['tabname'];
$nestedData["file_path"] = $path;
$nestedData["file_path2"] = $path2;
$nestedData["status"] = $show;
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval($requestData['draw']),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totalFiltered),
"data" => $data
);
echo json_encode($json_data);
?>