duankeng2026 2017-01-02 20:55
浏览 21

使用foreach循环显示数据库

I'm trying to display a database of items, the database (using mySQL) and PHPStorm are 100% linked. When I run the site the column names are displayed and it says that there is an error in the header of foreach loop (code from phtml file):

<?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>';
}
?>

'productDataSet' is highlighted and reads "Field productDataSet not found in productDataSet(php file)", also all get methods are highlighted and display that they cannot be found. They are situated in my productData.php file. Sorry if this is messy and I don't explain this very well. I'm new to PHP.

Code for ProductData:

class ProductData {
    protected $_id, $_product_name, $_product_price, $_product_desc,    $_product_manufacturer, $_quantity_in_stock, $_photo_name;

    public function __construct($dbRow) {
        $this->_id = $dbRow['id'];
        $this->_product_name = $dbRow['product_name'];
        $this->_product_price = $dbRow['product_price'];
        $this->_product_desc = $dbRow['product_desc'];
        $this->_product_manufacturer = $dbRow['product_manufacturer'];
        $this->_quantity_in_stock = $dbRow['quantity_in_stock'];
        $this->_photo_name = $dbRow['photo_name'];
    }

    public function getProductID() {
        return $this->_id;
    }

    public function getProductName() {
        return $this->_product_name;
    }

    public function getProductPrice() {
        return $this->_product_price;
    }

    public function getProductDesc() {
        return $this->_product_desc;
    }

    public function getProductManufacturer() {
        return $this->_product_manufacturer;
    }

    public function getQuantity() {
        return $this->_quantity_in_stock;
    }

    public function getPhotoName() {
        return $this->_photo_name;
    }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥170 如图所示配置eNSP
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果