0

我正在尝试获取所有通过产品 ID 提交和传递的投标金额,我似乎无法让它工作,谁能告诉我我做错了什么?

我已将视图类放置在它的输出上,并将查询放置在 DB 类上

我要做的是通过传递用户点击产品的链接从投标表中获取所有投标并输出到屏幕


<?php

class ProductView extends View {
    protected function displayContent() {
        if(isset($_GET['id'])) {
        //get the record from database
            $this -> product = $this -> model -> getProductByID($_GET['id']);
            $this -> bidprice = $this -> model ->allbids($_GET['id']);
                if(is_array($this -> product)) {
                    $html = $this -> displayProduct();
                    } else {

                       $html .= '<p>Sorry, that product is not available</p>';

                    }            
                        } else {
                         header("Location:index.php?page=error");

        }
            return $html;
    }


    private function displayProduct() {

            $html = '<div id="product">';
            $html .= '<img src="images/products/'.$this -> product['productImage'].'" alt="'.$this -> product['productName'].'" />';
            $html .= '<h3>'.$this -> product['productName'].'</h3>';
            $html .= '<p><strong>$'.$this -> product['productPrice'].'.00'.'</strong></p>';
            //.sprintf("%.2f" result was breaking the query placed .00. to give it currency rate.
            $html .= '<p>'.$this -> product['productDescription'].'</p>';
            $html .= '<p>'.$this -> bidprice['bidPrice'].'</p>';

            $html .= '</div>';
            $html .='<div id="space">';
            $html .='</div>';

        return $html;        
    }    
}



?>

数据库查询类

public function allbids($id){
        $qry = "SELECT userName , bidPrice as bidPrice FROM bids , users WHERE productID = $id";
        $rs = $this -> db -> query($qry);
        if($rs) {
            if($rs ->num_rows > 0) {
                $bid = $rs -> fetch_assoc();

            }
            return $bidPrice;

        } else {
            echo 'Error Executing Query';   
        }
        return false;
    }
4

1 回答 1

0

我认为您只是从投标表中获取了一条记录,而且 allbids 函数似乎不正确,请尝试使用下面的代码,让我知道它是否适合您。

<?php

class ProductView extends View {
protected function displayContent() {
    if(isset($_GET['id'])) {
    //get the record from database
        $this -> product = $this -> model -> getProductByID($_GET['id']);
        $this -> bidprice = $this -> model ->allbids($_GET['id']);
            if(is_array($this -> product)) {
                $html = $this -> displayProduct();
                } else {

                   $html .= '<p>Sorry, that product is not available</p>';

                }            
                    } else {
                     header("Location:index.php?page=error");

    }
        return $html;
}


private function displayProduct() {

        $html = '<div id="product">';
        $html .= '<img src="images/products/'.$this -> product['productImage'].'" alt="'.$this -> product['productName'].'" />';
        $html .= '<h3>'.$this -> product['productName'].'</h3>';
        $html .= '<p><strong>$'.$this -> product['productPrice'].'.00'.'</strong></p>';
        //.sprintf("%.2f" result was breaking the query placed .00. to give it currency rate.
        $html .= '<p>'.$this -> product['productDescription'].'</p>';
        /* here you have to place a for each loop that will fetch all the info for bid*/
        foreach($this -> bidprice as $val)
        {
            $html .= '<p> Bid Price'.$val['bidPrice'].'</p>';
            $html .= '<p> Bidded By'.$val['userName'].'</p>';
        }

        $html .= '</div>';
        $html .='<div id="space">';
        $html .='</div>';

    return $html;        
}    

}

// your db function
public function allbids($id){
    $qry = "SELECT userName , bidPrice as bidPrice FROM bids , users WHERE productID = $id";
    $rs = $this -> db -> query($qry);
    if($rs) {
        if($rs ->num_rows > 0) {
            while($row = mysql_fetch_assoc($rs))
            {
                $bid[]= $row;
            }

        }
        return $bid[];

    } else {
        echo 'Error Executing Query';   
    }
    return false;
}
?>
于 2013-04-06T12:02:27.363 回答