connect_error) { die("Could not connect to the database"); } function parseQuery() { return [ 'published' => filter_input( INPUT_GET, 'published', FILTER_VALIDATE_BOOLEAN) ?? false, 'preview' => filter_input( INPUT_GET, 'preview') ]; } function loadArticles($connection, $query) { $stmt_string = 'SELECT * FROM articles WHERE preview LIKE ?'; if ($query['published']) { $stmt_string .= ' AND published IS NOT NULL'; } $stmt = $connection->prepare($stmt_string) or handle_error($connection); $search_string = "%".$query['preview']."%"; $stmt->bind_param('s', $search_string) or handle_error($connection); $stmt->execute() or handle_error($connection); $stmt_result = $stmt->get_result() or handle_error($connection); $result = []; while ($row = $stmt_result->fetch_assoc()) { $result[$row['id']] = $row; } return $result; } function handle_error($connection) { die("Query error: " . $connection->error); } $query = parseQuery(); $items = loadArticles($connection, $query); $connection->close(); ?> Items list

Items

>
>