<?php $db_host = "localhost"; $db_name = "Office_E"; $db_user = "root"; $db_pass = ""; try{ $con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e){ echo $e->getMessage(); } ?>
<pre>?php include 'config.php'; ## Read value $draw = $_POST['draw']; $row = $_POST['start']; $rowperpage = $_POST['length']; // Rows display per page $columnIndex = $_POST['order'][0]['column']; // Column index $columnName = $_POST['columns'][$columnIndex]['data']; // Column name $columnSortOrder = $_POST['order'][0]['dir']; // asc or desc $searchValue = $_POST['search']['value']; // Search value ## Search $searchQuery = " "; if($searchValue != ''){ $searchQuery = " and (emp_no like '%".$searchValue."%' or first_name like '%".$searchValue."%' or last_name like'%".$searchValue."%' ) "; } ## Total number of records without filtering - PDO style // Count Total Records in the table $totalRecords = $con->query("SELECT count(*) from employees")->fetchColumn(); ## Total number of records with filtering - PDO Style $totalRecordwithFilter = $con->query("SELECT count(*) from employees WHERE 1 ".$searchQuery)->fetchColumn(); ## Fetch records - PDO style $data = array(); // bind values.. $stmt = $con->prepare("select * from employees WHERE 1 ".$searchQuery." order by ".$columnName." ".$columnSortOrder." limit ".$row.",".$rowperpage;); //$stmt->bindParam(1, $start,PDO::PARAM_INT); //$stmt->bindParam(2, $end,PDO::PARAM_INT); $stmt->execute(); $data1 = $stmt->fetchAll(); if ($stmt->fetchcolumn() > 0) { foreach ($data1 as $row) { $data[] = array ( "emp_no"=>$row['emp_name'], "first_name"=>$row['first_name'], "last_name"=>$row['last_name'], "gender"=>$row['gender'], "hire_date"=>$row['hire_date'] ); } unset($data1); }
"emp_no"=>$row['emp_name'],
"emp_no"=>$row['emp_no'],
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)