0
我實際上在PHP中編寫一個類和一個DAO類,如下所示: dbDAO內容只有我的數據庫PDO連接。我想要在我的索引頁上顯示我的數據庫包含的所有產品。從我的數據庫中顯示所有產品的最佳方法是什麼,它是在我的DAO類中還是使用對象產品? DAO類僅用於修改數據庫中的內容?從數據庫顯示數據與類和DAO
這裏是我的代碼:
DAO類:
class ProduitDao extends dbDAO
{
public function displayProduits()
{
$product = $this->bdd->prepare("SELECT * FROM products");
$product->execute();
while ($displayProduct = $product->fetch())
{
?>
<div class="prodname">
<?php
echo '<a href="./product.php?id='.$displayProduct['no'].'"</a>';
echo '<img src="images/produits/'.$displayProduct['image'].'" alt=" '.$affichageProduit['nom'].' "</img>';
?>
</div>
<?php
}
}
產品類:
public function __construct($no, $img)
{
$this->no = $numero;
$this->img = $img;
}
// GET and SET goes here
Tancks!
我現在看到的! Tancks的幫助! :) – SurveyVisual