I am trying to display a database using a for-each loop, however each of my get methods are highlighted and display that they cannot be found in my other class. I am very new to PHP and have no idea why this error is occurring.
For-Each Loop:
<?php foreach ($view->productDataSet as $productData) {
echo '<td>'.$productData->getProductID().
'</td><td>'.$productData->getProductName().
'</td><td>'.$productData->getProductPrice().
'</td><td>'.$productData->getProductDesc().
'</td><td>'.$productData->getProductManufacturer().
'</td><td>'.$productData->getQuantity().
'</td><td>'.'<img src="images/'.$productData->getPhotoName().'" alt="no picture"/>'.
'</td> </td>';
} ?>
</tbody>
I believe the problem is occurring in the line $view->productDataSet as $productData
however I don't really know what this line of code means. The class below is my productDataSet class which calls the sql query that should display the table.
class ProductsDataSet {
protected $_dbHandle, $_dbInstance;
public function __construct() {
$this->_dbInstance = Database::getInstance();
$this->_dbHandle = $this->_dbInstance->getdbConnection();
}
public function fetchAllProducts() {
$sqlQuery = 'SELECT * FROM products';
echo $sqlQuery;
$statement = $this->_dbHandle->prepare($sqlQuery); // prepare a PDO statement
$statement->execute(); // execute the PDO statement
$dataSet = [];
while ($row = $statement->fetch()) {
$dataSet[] = new ProductData($row);
}
return $dataSet;
}
Sorry if this is isn't set out well. Any ideas?