query('SELECT COUNT(*) FROM admin_audit_log')->fetchColumn(); $stmt = $pdo->prepare( 'SELECT al.*, s.name AS staff_name FROM admin_audit_log al LEFT JOIN staff s ON s.id = al.staff_id ORDER BY al.created_at DESC LIMIT ? OFFSET ?' ); $stmt->bindValue(1, $perPage, PDO::PARAM_INT); $stmt->bindValue(2, $offset, PDO::PARAM_INT); $stmt->execute(); $entries = $stmt->fetchAll(); api_json([ 'items' => array_map(fn(array $e) => [ 'id' => (int) $e['id'], 'staffName' => $e['staff_name'], 'action' => $e['action'], 'createdAt' => $e['created_at'], ], $entries), 'page' => $page, 'perPage' => $perPage, 'total' => $total, 'hasMore' => $offset + count($entries) < $total, ]);