0){ $where[] = "posts.category_id = ?"; $params[] = $categoryId; $types .= "i"; } if(!empty($where)){ $query .= " WHERE " . implode(" AND ", $where); } $query .= " ORDER BY posts.created_at DESC"; $stmt = $conn->prepare($query); if(!empty($params)){ $stmt->bind_param($types, ...$params); } $stmt->execute(); $posts = $stmt->get_result(); /* FETCH CATEGORIES */ $catSql = " SELECT post_categories.id, post_categories.name, COUNT(posts.id) AS total FROM post_categories LEFT JOIN posts ON posts.category_id = post_categories.id GROUP BY post_categories.id ORDER BY post_categories.name ASC "; $categories = $conn->query($catSql); ?> News List
Home Company News

Categories

    fetch_assoc()): ?>
fetch_assoc()): ?>