PDO搜索中的PDO不显示所有结果

时间:2014-10-10 13:26:19

标签: php mysql pdo

我有非常简单的功能(基本上一直在做同样的事情),它试图一次从3个表中获取数据,然后在现场显示它。问题是数据库上的最后一次PDO连接会导致结果出现问题。

详细说明: 如果我使用这样的代码(最后一次连接被注释,它在表axnmrs_positions上)它显示所有resutls和1 VIN的所有数据(ofc没有来自通信表的数据)它应该如何。但如果我取消注释它,它只显示单个结果,我不知道为什么。问题介于几条评论线和结尾之间,但无法找到位置。

我需要什么: 让代码查找并显示所有3个表的所有结果,而不仅仅是单个表

P.S。我知道CODE很糟糕,但它是我开始使用PHP OOP / PDO等等,所以请尊重我的学习:)

我的代码:

     public function fetchByVinAxnmrss($con) {
         $success = false;
         //$this->vin = "KMHLC81UACU021096";
         if($this->vin){
         try{
            $sql = "SELECT * FROM axnmrs_cases WHERE vin = :vin LIMIT 30";
            $stmt = $con->prepare( $sql );
            $stmt->bindValue( "vin", $this->vin, PDO::PARAM_STR );
            $stmt->execute();
                while ($row = $stmt->fetch()){
                    echo"<tr>";
                    echo  "<td class='number'>".$row['claimnumber']."</td>";
                    // Remove time from date
                    $date = substr($row['date_created'], 0, -9); 
                    echo  "<td class='city'>".$date."</td>"; 
                    //echo  "<td class='street'>Axnmrs</td>";
                    // Which Insurer work on it? 
                    switch ($row['insurer_memberid']) {
                        case "MM-O-37C4CD31-1":
                            echo  "<td class='case'>Allianz</td>";
                            break;
                        case "MM-O-679147C3":
                            echo "<td class='case'>Česká pojišťovna</td>";
                            break; 
                        case "MM-O-8484AD31-2":
                            echo "<td class='case'>Česká pojišťovna</td>";
                            break; 
                        case "MM-O-8484AD31":
                            echo "<td class='case'>Česká pojišťovna</td>";
                            break; 
                        case "MM-O-78EFD7AF":
                            echo "<td class='case'>Česká pojišťovna</td>";
                            break; 
                        case "MM-O-26D1C0EF":
                            echo "<td class='case'>Servisní pojišťovna</td>";
                            break;  
                        case "MM-O-D45A6DEF":
                            echo "<td class='case'>Triglav Pojišťovna</td>";
                            break;  
                        case "MM-O-26D1C0EF":
                            echo "<td class='case'>Servisní pojišťovna</td>";
                            break;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                        default:
                            echo "<td class='case'>Servis</td>";                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                    } 

                    echo  "<td class='country'>".$row['country']."</td>";
                    echo  "<td class='action'><button class='btn btn-flat btn-view'><span class='glyphicon glyphicon-eye-open' title='Show Detail'></span></button></td>";                    
                    echo"</tr>";

                  echo"<tr class='detail'>";
                   echo"<td colspan='6'>";
                      echo "<div class='case-detail row'>";  
                      echo  "<div class='col-xs-6 col-md-3'>";      
                          echo"<dl>";
                          // What parts are used
                          echo  "<dt>Použité náhradní díly</dt>";
                          if ($row['part_supplier']=1){
                          echo  "<dd>Originální</dd>";}
                          else{
                          echo  "<dd>Alternativní</dd>";}

                          echo  "<dt>Datum vytvoření případu</dt>";
                          echo  "<dd>".$row['date_created']."</dd>";

                          echo  "<dt>SPZ</dt>";
                          echo  "<dd>".$row['platenumber']."</dd>";

                          echo  "<dt>Totální škoda</dt>";
                          if (empty($row['totalloss'])){
                          echo $row['totalloss'];    
                          echo  "<dd>Ne</dd>";}
                          else{
                          echo  "<dd>Ano</dd>";}                            

                          echo  "<dt>VIN</dt>";
                          echo  "<dd>".$row['vin']."</dd>";   

                          $this->manufacturer_code = $row['lastcalc_manufacturer_code'];
                          $this->main_type = $row['lastcalc_model_code'];
                          $this->subtype_code = $row['lastcalc_submodel_code'];  

                          echo  "<dt>Druh vozidla</dt>";
                          echo  "<dd>".$this->getCarType()."</dd>";                          

                          echo"</dl>";
                        echo"</div>";
                        // DRUHY STLPEC
                        echo"<div class='col-xs-6 col-md-3'>";
                          echo"<dl>";

                          echo  "<dt>Identifikace vozidla pomocí AudaVIN</dt>";
                          if (isset($row['audavin_trigged'])){
                          echo  "<dd>Ano</dd>";}
                          else{
                          echo  "<dd>Ne</dd>";}                          
                          // DATUM NEHODY
                          echo  "<dt>Datum nehody</dt>";
                          if ($row['accident_date'] == "0000-00-00 00:00:00"){
                              echo "<dd>Neni k dispozici</dd>";
                          }
                          else{
                          echo  "<dd>".$row['accident_date']."</dd>";
                          }
                          // DATUM REGISTRACE VOZIDLA
                          echo  "<dt>Datum registrace vozidla</dt>";
                          if ($row['registration_date'] == "0000-00-00 00:00:00"){
                              echo "<dd>Neni k dispozici</dd>";
                          }
                          else{
                          echo  "<dd>".substr($row['registration_date'], 0, 10)."</dd>"; 
                          }

                     $this->case = $row['case_id'];
                     try{
                        $sql = "SELECT * FROM axnmrs_calculations WHERE case_id = :case LIMIT 1";
                        $stmt_calculations = $con->prepare( $sql );
                        $stmt_calculations->bindValue( "case", $this->case, PDO::PARAM_STR );
                        $stmt_calculations->execute();                   
                        while ($row = $stmt_calculations->fetch()){

                          $this->calculationid = $row['calculation_id'];

                          echo  "<dt>Cena náhradních dílů</dt>";
                          echo  "<dd>".$row['spareparts']."</dd>";

                          echo  "<dt>Celkové náklady</dt>";
                          echo  "<dd>".$row['totalcosts']."</dd>";                           
                          echo"</dl>";
                        echo"</div>"; 

                        echo"<div class='col-xs-6 col-md-3'>";
                          echo"<dl>";
                          echo  "<dt>Celkový počet hodin práce</dt>";
                          echo  "<dd>".$row['laborhours']."</dd>";

                          echo  "<dt>Datum vytvoření kalkulace</dt>";
                          echo  "<dd>".substr($row['calculationdate'], 0, 17)."</dd>";      // ODSTRANIT 0000

                          echo  "<dt>Lakovací materiál</dt>";
                          echo  "<dd>".$row['paintmaterial']."</dd>";

                          echo  "<dt>Náklady na práci</dt>";
                          echo  "<dd>".$row['laborcosts']."</dd>";

                          echo  "<dt>Náklady na lakování</dt>";
                          echo  "<dd>".$row['paintlabor']."</dd>";                                                    

                          echo  "<dt>Měna</dt>";
                          echo  "<dd>".$row['currency']."</dd>";  
                          echo"</dl>";
                        echo"</div>";                                                                             
                          }

                            }catch(PDOExeption $e){
                            echo $e->getMessage();
                            echo $con->errorInfo();
                            } 

                        echo"<div class='col-xs-6 col-md-3'>";
                          echo"<dl>";
                          echo  "<dt>Seznam použitých náhradních dílů </dt>";
                        //$this->calculationid = $row['calculation_id'];

                        try{
                            echo "NECO";
                        /*
                        $sql = "SELECT * FROM axnmrs_positions WHERE calculation_id = :calculationid LIMIT 60";
                        $stmt_position = $con->prepare( $sql );       
                        $stmt_position->bindValue( "calculationid", $this->calculationid, PDO::PARAM_STR );
                        $stmt_position->execute();
                        while ($row = $stmt_position->fetch()){ 
                        echo  "<dd>".$row['text']."</dd>";  
                            }
                        */    
                        }catch(PDOExeption $e){
                        echo $e->getMessage();
                        echo $con->errorInfo();
                            } 
                        /*    
                          echo"</dl>";
                        echo"</div>"; 

                return $success;  
                */
                echo"</div>";
                echo "</td>" ;
                echo "</tr>";
                }
                }catch(PDOExeption $e){
                echo $e->getMessage();
                echo $con->errorInfo();
                }
                return $success;
             }             
         }  




     public function getCarType() {
         /*
         $this->manufacturer_code = "00";
         $this->main_type = "03";
         $this->subtype_code = "05";
          */
         $success = false;
         try{
            $con = new PDO( DB_HOST, DB_USER, DB_PASS ); 
            $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
            $sql = "SELECT * FROM car_type WHERE manufacturer_code = :manufacturer_code AND main_type = :main_type AND subtype_code = :subtype_code LIMIT 1";
            $stmt_car = $con->prepare( $sql );
            $stmt_car->bindValue( "manufacturer_code", $this->manufacturer_code, PDO::PARAM_STR );
            $stmt_car->bindValue( "main_type", $this->main_type, PDO::PARAM_STR );
            $stmt_car->bindValue( "subtype_code", $this->subtype_code, PDO::PARAM_STR );
            $stmt_car->execute();
                while ($row = $stmt_car->fetch()){
                    echo $row['manufacturer'];
                    echo "&nbsp;";
                    echo $row['model'];
                    echo "&nbsp;";
                    echo $row['submodel'];
                }
                }catch(PDOExeption $e){
                echo $e->getMessage();
                echo $con->errorInfo();
                }

             return $success; 
         }               
               echo  "<dd>Ano</dd>";}
                          else{
                          echo  "<dd>Ne</dd>";}                          
                          // DATUM NEHODY
                          echo  "<dt>Datum nehody</dt>";
                          if ($row['accident_date'] == "0000-00-00 00:00:00"){
                              echo "<dd>Neni k dispozici</dd>";
                          }
                          else{
                          echo  "<dd>".$row['accident_date']."</dd>";
                          }
                          // DATUM REGISTRACE VOZIDLA
                          echo  "<dt>Datum registrace vozidla</dt>";
                          if ($row['registration_date'] == "0000-00-00 00:00:00"){
                              echo "<dd>Neni k dispozici</dd>";
                          }
                          else{
                          echo  "<dd>".substr($row['registration_date'], 0, 10)."</dd>"; 
                          }

                     $this->case = $row['case_id'];
                     try{
                        $sql = "SELECT * FROM axnmrs_calculations WHERE case_id = :case LIMIT 1";
                        $stmt_calculations = $con->prepare( $sql );
                        $stmt_calculations->bindValue( "case", $this->case, PDO::PARAM_STR );
                        $stmt_calculations->execute();                   
                        while ($row = $stmt_calculations->fetch()){

                          $this->calculationid = $row['calculation_id'];

                          echo  "<dt>Cena náhradních dílů</dt>";
                          echo  "<dd>".$row['spareparts']."</dd>";

                          echo  "<dt>Celkové náklady</dt>";
                          echo  "<dd>".$row['totalcosts']."</dd>";                           
                          echo"</dl>";
                        echo"</div>"; 

                        echo"<div class='col-xs-6 col-md-3'>";
                          echo"<dl>";
                          echo  "<dt>Celkový počet hodin práce</dt>";
                          echo  "<dd>".$row['laborhours']."</dd>";

                          echo  "<dt>Datum vytvoření kalkulace</dt>";
                          echo  "<dd>".substr($row['calculationdate'], 0, 17)."</dd>";      // ODSTRANIT 0000

                          echo  "<dt>Lakovací materiál</dt>";
                          echo  "<dd>".$row['paintmaterial']."</dd>";

                          echo  "<dt>Náklady na práci</dt>";
                          echo  "<dd>".$row['laborcosts']."</dd>";

                          echo  "<dt>Náklady na lakování</dt>";
                          echo  "<dd>".$row['paintlabor']."</dd>";                                                    

                          echo  "<dt>Měna</dt>";
                          echo  "<dd>".$row['currency']."</dd>";  
                          echo"</dl>";
                        echo"</div>";                                                                             
                          }

                            }catch(PDOExeption $e){
                            echo $e->getMessage();
                            echo $con->errorInfo();
                            } 

                        echo"<div class='col-xs-6 col-md-3'>";
                          echo"<dl>";
                          echo  "<dt>Seznam použitých náhradních dílů </dt>";
                        //$this->calculationid = $row['calculation_id'];

                        try{
                            echo "NECO";                        
                        $sql = "SELECT * FROM axnmrs_positions WHERE calculation_id = :calculationid LIMIT 60";
                        $stmt_position = $con->prepare( $sql );
                        /*
                        $stmt_position->bindValue( "calculationid", $this->calculationid, PDO::PARAM_STR );
                        $stmt_position->execute();
                        while ($row = $stmt_position->fetch()){ 
                        echo  "<dd>".$row['text']."</dd>";  
                            }
                        */    
                        }catch(PDOExeption $e){
                        echo $e->getMessage();
                        echo $con->errorInfo();
                            } 
                        /*    
                          echo"</dl>";
                        echo"</div>"; 

                return $success;  
                */
                echo"</div>";
                echo "</td>" ;
                echo "</tr>";
                }
                }catch(PDOExeption $e){
                echo $e->getMessage();
                echo $con->errorInfo();
                }
                return $success;
             }             
         }  




     public function getCarType() {
         /*
         $this->manufacturer_code = "00";
         $this->main_type = "03";
         $this->subtype_code = "05";
          */
         $success = false;
         try{
            $con = new PDO( DB_HOST, DB_USER, DB_PASS ); 
            $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
            $sql = "SELECT * FROM car_type WHERE manufacturer_code = :manufacturer_code AND main_type = :main_type AND subtype_code = :subtype_code LIMIT 1";
            $stmt = $con->prepare( $sql );
            $stmt_cartype->bindValue( "manufacturer_code", $this->manufacturer_code, PDO::PARAM_STR );
            $stmt_cartype->bindValue( "main_type", $this->main_type, PDO::PARAM_STR );
            $stmt_cartype->bindValue( "subtype_code", $this->subtype_code, PDO::PARAM_STR );
            $stmt_cartype->execute();
                while ($row = $stmt_cartype->fetch()){
                    echo $row['manufacturer'];
                    echo "&nbsp;";
                    echo $row['model'];
                    echo "&nbsp;";
                    echo $row['submodel'];
                }
                }catch(PDOExeption $e){
                echo $e->getMessage();
                echo $con->errorInfo();
                }

             return $success; 
         }               


 }

0 个答案:

没有答案