ok
Direktori : /home2/selectio/www/frames-hub/data-tables/ |
Current File : //home2/selectio/www/frames-hub/data-tables/customer-dt.php |
<?php include("../api/config/config.php"); $requestData= $_REQUEST; $condition=''; if(isset($_POST['date'])){ $condition.=" and date between '".$_POST['date']."' and '".$_POST['date']."' "; } /*Fetch Database column Details*/ $columns = array( 0 =>'id', 1 =>'id', 2 =>'firstname', 3 =>'mobile', 4 =>'email', 5 =>'status', ); /*Fetch All Data Start*/ $statement = $pdo->prepare("SELECT * FROM customer where status=1 ORDER BY id DESC"); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); /*Fetch All Data End*/ /*Fetch Filter Data Start*/ $sql="SELECT * FROM customer where 1=1 and status=1 $condition"; if( !empty($requestData['search']['value']) ) { $sql.=" AND ( id LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR cust_firstname LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR cust_phone LIKE '%".$requestData['search']['value']."%' "; $sql.=" OR cust_lastname LIKE '%".$requestData['search']['value']."%' ) "; } $statement = $pdo->prepare($sql); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $totalFiltered = $statement->rowCount(); /*Fetch Filter Data End*/ $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; $statement = $pdo->prepare($sql); $statement->execute(); $query = $statement->fetchAll(PDO::FETCH_ASSOC); $data = array(); $i=$requestData['start']+1; foreach($query as $row ) { // preparing an array $nestedData=array(); $action_buttons= "<div ><div>"; $action_buttons.=" <a style='padding: 6px;' href='customer-edit.php?id=".$row["id"]."' data-toggle='ajax-modal' title='Update Customer' class='tip btn btn-warning btn-xs'> <i class='fa fa-edit'></i> EDIT </a> "; $action_buttons.='<button style="padding: 6px;" title="Delete Customer" onClick="delete_customer('.$row["id"].')" class="tip btn btn-danger btn-xs"> <i class="fa fa-trash-o"></i> DELETE </button>'; $action_buttons.="</div></div>"; $customer_details='<a ><b>'.$row['cust_firstname'].' '.$row['cust_lastname'].'</b></a>'; if(isset($row['cust_phone'])){ $customer_details.="<br>Mobile :<b>".$row['cust_phone']."</b>";} if(isset($row['email'])){ $customer_details.="<br>Email :<b>".$row['email']."</b>";} $nestedData[] = $i; $nestedData[] = $customer_details; /* $nestedData[] = $address_details; $nestedData[] = $pincode_details;*/ $nestedData[] = $action_buttons; $data[] = $nestedData; $i++; } $json_data = array( "draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. "recordsTotal" => intval( $totalData ), // total number of records "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData "data" => $data // total data array ); echo json_encode($json_data); // send data as json format ?>