-1
我是trieng从数据库列表项目,但结果出来两个。每个记录显示2个结果。目前我只有一个记录在数据库中,但是当我在屏幕上显示它时,它被重新修复。我不知道为什么会发生这种情况,我尝试过一个计数器,看看循环有多少次,结果总是一次。但结果显示两次。在php和mysql中重复记录
的代码如下:
<section class="container">
<div class="row">
<?php
if($bidCollection->selectBidsByStatusAndAppId(BidAccount::OPEN_NEW, $id)){
foreach($bidCollection->getBids() as $bid){
$banker->find($bid->getCustomerId());
$counter=0;
?>
<div class='col-xs-12 bg-more-light-gray bidlist'>
<div class="col-xs-12 col-sm-1 col-md-1">
<?php
if(!$uploader->findProfilePicture($banker->data()->_customer_id)){
echo "<img src='image/holder.png ' width='50' height='50' class='img-responsive' />";
}else{
echo "<img src='upload/proPicture/".$uploader->data()->pictureUrl."' width='50' height='50' class='img-responsive'/>";
}
?>
</div>
<div class="col-xs-12 col-sm-8 col-md-8">
<?php
echo '<h2>Agent name :'.$validate->cleanInput($banker->data()->officer_name).'</h2>';
echo '<h3>Institute name : '.$validate->cleanInput($banker->data()->bank_name).' '.++$counter.'</h3>';
if($bid->getApplicationOwnerId() === $customer->data()->_customer_id){
echo "<p>CheckBook: ";
if($bid->getRequestCheckBook()){echo "Yes";}else{echo "No";}
echo "</p>";
echo"<p> Minimum Deposit: AED ".$bid->getMinDeposit()."</p>";
echo"<p> Direct Debit Card: ";
if($bid->getRequestCreditCard()){echo "Yes";}else{echo "No";}
echo "</p>";
echo"<p> Other Fees/Arrangement Fees: AED ".$bid->getFees(). "</p>";
echo"<p> Account Will be ready in: ".$bid->getSetupTime() ."</p>";
}
?>
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<?php
$datetime = new DateTime($bid->getDatePosted());
$date = $datetime->format('Y-m-d');
$time = $datetime->format('H:i:s');
echo '<h4> Date: '.$date.'<br/>Time: '.$time.'</h4>';
echo"<form method='POST' action='viewBanker.php'>";
echo "<input type='hidden' name='banker' value='".$bid->getCustomerId()."'>";
echo "<input type='submit' class ='btn btn-default' name='submit' value='View Profile'>";
echo "</form>";
echo'<br/>';
if($bid->getApplicationOwnerId() === $customer->data()->_customer_id){
echo"<form method='post' action='acceptAccountBid.php'>";
echo "<input type='hidden' value='".$bid->getCustomerId()."' name ='bankerId'/>";
echo "<input type='hidden' value='".$id."' name ='appid'/>";
echo "<input type='hidden' value='".$bid->getApplicationOwnerId()."' name='ownerId'>";
echo "<input class='btn btn-default' type='submit' value='Accept Offer' name='submit'>";
echo"</form>";
}
?>
</div>
</div>
<?php
}
}
?>
,返回的值的方法如下:
public function selectBidsByStatusAndAppId($status, $appid)
{
$sql = "SELECT * FROM accountBid WHERE application_id = :appId AND status = :st";
try {
$sth = $this->_db->getConnection()->prepare($sql);
$sth->bindValue(':appId', $appid);
$sth->bindValue(':st', $status);
$sth->execute();
} catch (Exception $e) {
$this->setAlert('danger', 'Information Presentation Error: ' . $e->getMessage());
}
foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $data) {
$this->addBid($data);
}
return true;
}
public function addBid($data = null)
{
$bid = new BidAccount($data);
$this->bids[] = $bid;
}
public function getBids()
{
return $this->bids;
}
'''$ bidCollection-> getBids()'''返回什么?在'foreach'''之前,加入'''echo“
getBids():
”;'''让我们知道你得到了什么。 –你可以将''''bidCollection-> getBids()'''移到foreach外面,并将它的值放入一个变量中,这样它只被调用一次。 –
getBids()返回对象的数组。它所做的只是返回Bid对象的集合,然后使用foreach提取每个对象并显示其内容。 – Salim