我正在尝试显示“名称”对象,但它不起作用。我似乎在使用 foreach 错误..我 print_r for $a 它显示了数组。有人可以帮忙吗。
public function product(){
$st = $this->db->prepare("select id, name, description, price from deals where quantity > 0 order by id desc");
$st->execute();
if ($st->rowCount() == 0){
echo "There are no products to display";
} else {
$a = $st->fetch(PDO::FETCH_OBJ)
foreach ($a as $products){
echo $products->name;
}
}
}