= ?'; $params[] = $startDate; } if ($endDate !== '') { $where[] = 'DATE(cn.created_at) <= ?'; $params[] = $endDate; } if ($companyName !== '') { $where[] = 'c.display_name LIKE ?'; $params[] = "%$companyName%"; } if ($industry !== '') { $where[] = 'c.industry = ?'; $params[] = $industry; } if ($category !== '') { $where[] = 'cn.need_category = ?'; $params[] = $category; } $whereSql = implode(' AND ', $where); $pdo = DB::getInstance()->getPdo(); $stmt = $pdo->prepare( "SELECT COUNT(*) FROM company_needs cn LEFT JOIN companies c ON c.id = cn.company_id WHERE $whereSql" ); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT cn.id, cn.company_id, c.display_name, c.industry, cn.contact_person, cn.need_category, cn.target_product_category, cn.application_scenario, cn.description, cn.is_valid, cn.created_at FROM company_needs cn LEFT JOIN companies c ON c.id = cn.company_id WHERE $whereSql ORDER BY cn.id DESC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);