duanbage2161 2017-01-03 17:29
浏览 46

通过for-each循环显示数据库

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化