prepare('SELECT p.*, (SELECT m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id WHERE pm.product_id = p.id ORDER BY pm.position ASC LIMIT 1) AS img FROM products p WHERE p.status = 1 AND p.name LIKE ? ORDER BY p.date_added DESC'); // bindValue will allow us to use integer in the SQL statement, we need to use for LIMIT $stmt->execute(['%' . $search_query . '%']); // Fetch the products from the database and return the result as an Array $products = $stmt->fetchAll(PDO::FETCH_ASSOC); // Get the total number of products $total_products = count($products); } else { // Simple error, if no search query was specified why is the user on this page? $error = 'No search query was specified!'; } ?> =template_header('Search')?>
=$error?>
=$total_products?> Product=$total_products!=1?'s':''?>