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



?>

DB クエリ クラス

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 に答える