'preliminary']); [$page, $limit] = pageParams(); $keyword = trim($_REQUEST['keyword'] ?? ''); $sourceType = trim($_REQUEST['source_type'] ?? ''); $startDate = trim($_REQUEST['start_date'] ?? ''); $endDate = trim($_REQUEST['end_date'] ?? ''); $where = ['is_active = 1']; $params = []; if ($keyword !== '') { $where[] = '(company_name LIKE ? OR person_name LIKE ? OR contact_phone LIKE ? OR contact_email LIKE ? OR description LIKE ?)'; $like = "%$keyword%"; array_push($params, $like, $like, $like, $like, $like); } if ($sourceType !== '') { $where[] = 'source_type = ?'; $params[] = $sourceType; } if ($startDate !== '') { $where[] = 'DATE(created_at) >= ?'; $params[] = $startDate; } if ($endDate !== '') { $where[] = 'DATE(created_at) <= ?'; $params[] = $endDate; } $whereSql = implode(' AND ', $where); $pdo = DB::getInstance()->getPdo(); $stmt = $pdo->prepare("SELECT COUNT(*) FROM preliminary_data WHERE $whereSql"); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT id, source_type, company_name, person_name, contact_phone, contact_email, source_channel, recorded_by, follow_person, converted_type, converted_id, created_at, updated_at FROM preliminary_data WHERE $whereSql ORDER BY id DESC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);