我正试图抓住所有提交并通过产品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;
}
答案 0 :(得分:0)
我认为您刚刚从出价表中获取了单个记录,而且所有出价功能似乎都不正确,请尝试使用以下代码,让我知道是否为您工作。
<?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;
}
?>