Php查询无法从get?id加载查询
我正试图抓住所有的投标金额,已提交并通过产品ID,我似乎无法让它工作谁能告诉我我做错了请 我已经将视图类放置在DB类上,以便它输出和查询 我要做的是从bids表中抓取所有出价并输出到屏幕上 通过传递用户单击产品的链接Php查询无法从get?id加载查询,php,mysql,Php,Mysql,我正试图抓住所有的投标金额,已提交并通过产品ID,我似乎无法让它工作谁能告诉我我做错了请 我已经将视图类放置在DB类上,以便它输出和查询 我要做的是从bids表中抓取所有出价并输出到屏幕上 通过传递用户单击产品的链接 我想你刚刚从投标表中获取了一条记录,而且allbids函数似乎不正确,请尝试下面的代码,让我知道是否为你工作 <?php class ProductView extends View { protected function displayContent() {
我想你刚刚从投标表中获取了一条记录,而且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;
}
您好,在DB查询类中,您将返回一个未设置的变量。($bidPrice)。我猜应该是$bid。@JacksonYong:你知道为什么这对你不起作用吗?因为您只从bid表中获取一个bid,而您必须获取所有bid,并通过执行循环显示功能来显示。虽然如果您不清楚,请告诉我,我将通过编辑您的代码文件提供帮助。是的,对不起,我仍然不清楚:(我是php新手,你能教我吗me@JacksonYong:当然,我如何检查您的代码以及如何教您?因为我没有放置每个循环?@JacksonYong:是的,因为缺少循环,所以存在该问题,如果您需要,我可以解决此问题,与我共享您的文件和数据库结构。
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;
}
<?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;
}
?>