在php和mysql中重复记录

时间:2017-06-19 21:47:58

标签: php css mysql

我是trieng列出数据库的项目,但结果是两个。每条记录显示2个结果。目前我在数据库中只有一条记录,但是当我在屏幕上显示它们时,它会被修复。我不知道为什么会发生这种情况,我试图找到一个计数器,看看循环次数是多少次,结果总是一次。但结果显示两次。

代码如下:

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

1 个答案:

答案 0 :(得分:0)

首先,我要感谢我的朋友,他们曾试图帮助我。问题是我有另一个功能,我忘了在这里发布bidExist()

public function bidExist( $appId , $id){


        $sql = "SELECT * FROM accountBid WHERE application_id = :appId AND _customer_id = :id";
        try {

            $sth = $this->_db->getConnection()->prepare($sql);
            $sth->bindValue(':appId', $appId);
            $sth->bindValue(':id', $id);
            $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 $sth->rowCount();


    }

上面的函数循环遍历集合以检查并查看对象是否存在于此之前,如果是,那么您无法再添加出价,但是,我忘了删除此方法上的addBid()函数并导致要在集合中添加两次的对象。这让我彻夜难以理解。但我感谢所有试图支持和协助的人。