JezK
Edit File: getUsers.php
<?php include('adminObject.php'); $data = []; $limit = ""; $whereCondition = "WHERE delete_status = 0"; $tableColumns = array('user_name', 'phone', 'email', 'user_id'); if ($_POST['length'] != '-1') { $limit = "LIMIT " . $_POST['length']; } // For Search if ($_POST['search']['value'] != "") { $whereCondition = " "; $whereCondition = "WHERE delete_status = 0 AND ("; for ($i = 0; $i < count($tableColumns); $i++) { $whereCondition .= $tableColumns[$i] . " LIKE '%" . $_POST['search']['value'] . "%' OR "; } $whereCondition = substr_replace($whereCondition, "", -3); $whereCondition .= ') '; } // Query for no.of rows $totalRows = $admin->conn->prepare('SELECT `user_id`,`user_name`,`phone`,`email` FROM user ' . $whereCondition . ''); $totalRows->execute(); $totalRowsResult = $totalRows->rowcount(); // Query to show data $query = $admin->conn->prepare('SELECT `id`,`user_id`,`user_name`,`phone`,`email` FROM user ' . $whereCondition . ' ORDER BY `id` DESC LIMIT :limit OFFSET :offset'); $query->bindValue(':limit', $_POST['length'], PDO::PARAM_INT); $query->bindValue(':offset', $_POST['start'], PDO::PARAM_INT); $query->execute(); $queryData = $query->fetchAll(PDO::FETCH_ASSOC); $filterCount = $query->rowcount(); $j = 1; foreach ($queryData as $row) { $dataTableRow = array(); $dataTableRow[] = $_POST['start'] + $j; $dataTableRow[] = $row['user_name']; $dataTableRow[] = $row['email']; $dataTableRow[] = $row['user_id']; $id = $row['id']; $sql = "SELECT * FROM allotment WHERE type = 1 AND user_id = '$id' AND (approve_status=1 OR approve_status=4)"; $allotmentQuery = $admin->conn->prepare($sql); $allotmentQuery->execute(); $allotmentDetails = $allotmentQuery->fetchAll(PDO::FETCH_ASSOC); $sum = 0; $index = 0; $totalSum = 0; $serviceSum = 0; foreach ($allotmentDetails as $pointsDetails) { $vechicleDetails = $pointsDetails['vechile_details']; $vechicleDetails = unserialize($vechicleDetails); $servicePointsStatus = $vechicleDetails['servicePointsStatus']; // Array of Points Status 1-complted $details = $pointsDetails['details']; $singlePurchaseDetails = unserialize($details); $expiryDateString = $singlePurchaseDetails['expiryDate']; $expiryDate = DateTime::createFromFormat('d-m-Y', $expiryDateString); $servicePoints = json_decode($singlePurchaseDetails['servicePoints']); // Array Of Points $today = date('d-m-Y'); $todayDate = DateTime::createFromFormat('d-m-Y', $today); if ($todayDate < $expiryDate) { foreach ($servicePointsStatus as $index => $status) { if ($status == 0) { $sum += intval($servicePoints[$index]); } } } } // $dataTableRow[] = $sum; $dataTableRow[] = $row['phone']; //Passing user id in enctypt type $userId = $row['id']; $dataTableRow[] = '<a href="./edituser.php?userid=' . base64_encode($userId) . '" class="de-primary-color me-1"><i class="fas fa-eye"></i> <span class="icon-text"></span> </a>' . '<button class="de-delete" data-bs-toggle="modal" data-bs-target="#deleteModal" id="' . $row['id'] . '" onclick="getUserId(' . $row['id'] . ')"><i class="fas fa-trash-alt"></i> <span class="icon-text"></span> </button>'; $data[] = $dataTableRow; $j++; } $datatableResult = [ "draw" => $_POST['draw'], "recordsTotal" => $totalRowsResult, "recordsFiltered" => $totalRowsResult, "data" => $data ]; echo json_encode($datatableResult);