abstractindia

response.php

Dec 25th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1.  
  2. <?php
  3.     //include connection file
  4.     include_once("connection.php");
  5.      
  6.     // initilize all variable
  7.     $params = $columns = $totalRecords = $data = array();
  8.  
  9.     $params = $_REQUEST;
  10.  
  11.     //define index of column
  12.     $columns = array(
  13.         0 => '`Full Name`',
  14.         1 => 'Gender',
  15.         2 => 'CityName',
  16.         3 => 'CourseDescriptionLong',
  17.         4 => '`Subject`',
  18.         5 => 'ScholarshipAwarded',
  19.         6 => 'StudentID'
  20.     );
  21.  
  22.     $where = $sqlTot = $sqlRec = "";
  23.  
  24.     // check search value exist
  25.     if( !empty($params['search']['value']) ) {  
  26.         $where .=" WHERE ";
  27.         $where .=" (`Full Name` LIKE '".$params['search']['value']."%' ";    
  28.         $where .=" OR CityName LIKE '".$params['search']['value']."%' ";
  29.  
  30.         $where .=" OR CourseDescriptionLong LIKE '".$params['search']['value']."%' )";
  31.     }
  32.  
  33.     // getting total number records without any search
  34.     $sql = "SELECT fullnames.`Full Name`, studentdetails.Gender, lt_cities.CityName, lt_coursedescription.CourseDescriptionLong, lt_coursesubject.`Subject`, Sum(scholarshipdetails.ScholarshipAwarded), studentdetails.StudentID, coursedetails.CourseType, lt_coursedescription.CourseDescriptionShort, scholarshipdetails.ScholarshipYear FROM studentdetails INNER JOIN scholarshipdetails ON studentdetails.StudentID = scholarshipdetails.StudentID INNER JOIN coursedetails ON studentdetails.StudentID = coursedetails.StudentID AND scholarshipdetails.ScholarshipYear = coursedetails.Scholarshipyear LEFT JOIN lt_coursedescription ON coursedetails.CourseID = lt_coursedescription.CourseID INNER JOIN tuitionfeedetails ON studentdetails.StudentID = tuitionfeedetails.StudentID AND scholarshipdetails.ScholarshipYear = tuitionfeedetails.ScholarshipYear INNER JOIN fullnames ON studentdetails.StudentID = fullnames.StudentID INNER JOIN lt_cities ON lt_cities.CityID = studentdetails.City LEFT JOIN lt_coursesubject ON lt_coursesubject.CourseID = lt_coursedescription.CourseID AND lt_coursesubject.SubjectID = coursedetails.CourseSubject GROUP BY studentdetails.StudentID";
  35.     $sqlTot .= $sql;
  36.     $sqlRec .= $sql;
  37.     //concatenate search sql if value exist
  38.     if(isset($where) && $where != '') {
  39.  
  40.         $sqlTot .= $where;
  41.         $sqlRec .= $where;
  42.     }
  43.  
  44.  
  45.     $sqlRec .=  " ORDER BY ". $columns[$params['order'][0]['column']]."   ".$params['order'][0]['dir']."  LIMIT ".$params['start']." ,".$params['length']." ";
  46.  
  47.     $queryTot = mysqli_query($conn, $sqlTot) or die("database error:". mysqli_error($conn));
  48.  
  49.  
  50.     $totalRecords = mysqli_num_rows($queryTot);
  51.  
  52.     $queryRecords = mysqli_query($conn, $sqlRec) or die("error to fetch employees data");
  53.  
  54.     //iterate on results row and create new index array of data
  55.     while( $row = mysqli_fetch_row($queryRecords) ) {
  56.         $data[] = $row;
  57.     }  
  58.  
  59.     $json_data = array(
  60.             "draw"            => intval( $params['draw'] ),  
  61.             "recordsTotal"    => intval( $totalRecords ),  
  62.             "recordsFiltered" => intval($totalRecords),
  63.             "data"            => $data   // total data array
  64.             );
  65.  
  66.     echo json_encode($json_data);  // send data as json format
  67. ?>
Add Comment
Please, Sign In to add comment