BlaBla BlaBla - 6 months ago 20
MySQL Question

Getting a row from mySQL database if the price has been reduced

I am trying to display only the products that have reduced set as 'yes' in the database but i am receiving the following error:

Warning: Invalid argument supplied for foreach() in /reduced.php on line 79


reduced.php

<?php
$pdo = new PDO('mysql:host=localhost;dbname','name','password');
$reduced = 'yes';
$result = $pdo->query('SELECT file_id, productName, price, stock, reduced FROM files WHERE reduced = '.$reduced.'');
foreach($result as $row){
echo "<div id='shop'>";
echo "<img id='product' src=\"file.php?id={$row['file_id']}\">";
echo '<p>' . $row['productName'] . '</p>';
echo '<p>' . "£" . $row['price'] . '</p>';
echo '<p>' . "Stock Level: " . $row['stock'] . '</p>';
echo '<a href="basket.php">ADD TO BASKET</a>';
echo "</div>";
}
?>

Answer

It's the quotes try

 $result = $pdo->query('SELECT file_id, productName, price, stock, reduced FROM files WHERE reduced = "'.$reduced.'"');