2016-09-06 76 views
-5

我正在用php和mysql編程我的第一頁。現在我遇到了一個我自己無法解決的錯誤。如果看圖,前三列是case1,下一個是case2,最後一個是case3。 現在我的問題是,只有第一個和最後一個表格顯示正確。第二張和第三張表缺少「Distanz」欄。第四張桌子完全混在一起。php MySQL - 混合輸出

希望你能指出我的錯誤。提前致謝。

The output of given code

<?php 
$user_id = $_SESSION['userid']; 
$statement_anzeigeart = $pdo->prepare("SELECT id, name FROM sportart WHERE infoart_id = :infoart_id"); 
$statement_infoart_1 = $pdo->prepare("SELECT id, datum, dauer, distanz, hr, belast_koerp, belast_ment, gewicht FROM daten WHERE user_id = :user_id AND sportart = :sportart AND deleted = '0' ORDER BY datum LIMIT :limit"); 
$statement_infoart_2 = $pdo->prepare("SELECT id, datum, dauer, hr, saetze, wdhl, belast_koerp, belast_ment, gewicht FROM daten WHERE user_id = :user_id AND sportart = :sportart AND deleted = '0' ORDER BY datum LIMIT :limit"); 
$statement_infoart_3 = $pdo->prepare("SELECT id, datum, dauer, uebungen, hr, belast_koerp, belast_ment, gewicht FROM daten WHERE user_id = :user_id AND sportart = :sportart AND deleted = '0' ORDER BY datum LIMIT :limit"); 

include 'edit.inc.php'; 
include 'delete.inc.php'; 
?> 

<?php 
if(!isset($_GET['sportart'])){ 
    for($infoart_id=1;$infoart_id<=3;$infoart_id++){ 
     $statement_anzeigeart->execute(array($infoart_id)); 
     while($sportart_sql = $statement_anzeigeart->fetch()){ 
      $sportart = $sportart_sql['id']; 
      $limit = "3"; 

              $statement_infoart_3->execute(array('user_id' => $user_id, 'sportart' => $sportart, 'limit' => $limit)); 


      switch($infoart_id){ 
       case 1: 
        $statement_infoart_1->execute(array('user_id' => $user_id, 'sportart' => $sportart, 'limit' => $limit)); 

        echo "<div class='table-responsive'> 
          <h2 class='sub-header'><a href='?seite=report&sportart=".$sportart_sql['id']."'>".$sportart_sql['name']."</a> </h2> 
           <table class='table table-striped table-condensed'> 
            <thead> 
             <tr> 
              <th>Datum</th>     
              <th>Dauer</th> 
              <th>Distanz</th> 
              <th>HR</th> 
              <th>Belastung (physisch)</th> 
              <th>Belastung (mental)</th>     
              <th>Gewicht</th> 
              <th>Aktionen</th> 
             </tr> 
            </thead> 
            <tbody>"; 

        while($activity1 = $statement_infoart_1->fetch()){ 
         echo "   <tr> 
              <td>".$activity1['datum']."</td> 
              <td>".$activity1['dauer']."</td> 
              <td>".$activity1['distanz']."</td> 
              <td>".$activity1['hr']."</td> 
              <td>".$activity1['belast_koerp']."</td> 
              <td>".$activity1['belast_ment']."</td> 
              <td>".$activity1['gewicht']."</td> 
              <td><a href='?seite=report&edit=".$activity1['id']."' class='btn btn-default'><span class='glyphicon glyphicon-pencil'></span></a> <a href='?seite=report&delete=".$activity1['id']."' class='btn btn-default'><span class='glyphicon glyphicon-trash'></span></a></td> 
             </tr>"; 
        } //endwhile 
        echo   "</tbody> 
           </table>  
         </div>";     
        break; 
       case 2: 
        $statement_infoart_2->execute(array('user_id' => $user_id, 'sportart' => $sportart, 'limit' => $limit)); 

        echo "<div class='table-responsive'> 
          <h2 class='sub-header'><a href='?seite=report&sportart=".$sportart_sql['id']."'>".$sportart_sql['name']."</a> </h2> 
           <table class='table table-striped table-condensed'> 
            <thead> 
             <tr> 
              <th>Datum</th>     
              <th>Dauer</th> 
              <th>Sätze</th> 
              <th>Wdhl</th> 
              <th>HR</th> 
              <th>Belastung (physisch)</th> 
              <th>Belastung (mental)</th>     
              <th>Gewicht</th> 
              <th>Aktionen</th> 
             </tr> 
            </thead> 
            <tbody>"; 
        while($activity2 = $statement_infoart_2->fetch()){ 
         echo "   <tr> 
              <td>".$activity2['datum']." 1</td> 
              <td>".$activity2['dauer']." 2</td> 
              <td>".$activity2['saetze']." 3</td> 
              <td>".$activity2['wdhl']." 4</td> 
              <td>".$activity2['hr']." 5</td> 
              <td>".$activity2['belast_koerp']." 6</td> 
              <td>".$activity2['belast_ment']." 7</td> 
              <td>".$activity2['gewicht']." 8</td> 
              <td><a href='?seite=report&bearbeiten=".$activity2['id']."' class='btn btn-default'><span class='glyphicon glyphicon-pencil'></span></a> <a href='?seite=report&delete=".$activity2['id']."' class='btn btn-default'><span class='glyphicon glyphicon-trash'></span></a></td> 
             </tr>" ; 
        } //endwhile 
        echo   "</tbody> 
           </table>  
         </div>";       
        break; 
       case 3: 
       $statement_infoart_3->execute(array('user_id' => $user_id, 'sportart' => $sportart, 'limit' => $limit)); 
        echo "<div class='table-responsive'> 
          <h2 class='sub-header'><a href='?seite=report&sportart=".$sportart_sql['id']."'>".$sportart_sql['name']."</a> </h2> 
           <table class='table table-striped table-condensed'> 
            <thead> 
             <tr> 
              <th>Datum</th>     
              <th>Dauer</th> 
              <th>Übungen</th> 
              <th>HR</th> 
              <th>Belastung (physisch)</th> 
              <th>Belastung (mental)</th>     
              <th>Gewicht</th> 
              <th>Aktionen</th> 
             </tr> 
            </thead> 
            <tbody>"; 
        while($activity3 = $statement_infoart_3->fetch()){ 
         echo "   <tr> 
              <td>".$activity3['datum']."</td> 
              <td>".$activity3['dauer']."</td> 
              <td>".$activity3['uebungen']."</td> 
              <td>".$activity3['hr']."</td> 
              <td>".$activity3['belast_koerp']."</td> 
              <td>".$activity3['belast_ment']."</td> 
              <td>".$activity3['gewicht']."</td> 
              <td><a href='?seite=report&bearbeiten=".$activity3['id']."' class='btn btn-default'><span class='glyphicon glyphicon-pencil'></span></a> <a href='?seite=report&delete=".$activity3['id']."' class='btn btn-default'><span class='glyphicon glyphicon-trash'></span></a></td> 
             </tr>" ; 
        } //endwhile 
        echo   "</tbody> 
           </table>  
         </div>"; 
        break; 
      } 
     } // endwhile 
    } //endfor 
} //endif 
?> 
+2

沒辦法,我正在梳理這麼多的代碼......你能縮小它嗎?你有沒有檢查你的錯誤日誌? –

+0

調試這個最好的希望是嘗試創建一個非常小的例子。例如,如果您完全刪除除第二個表以外的所有內容,並且除了該表中的distanz列之外的所有內容。 –

+0

「$ statement_infoart_2」或「$ statement_infoart_3」中沒有'distanz'。爲什麼會出現這種情況? – Barmar

回答

0

不知道爲什麼,但在我交換仿真準備重新開啓,改變了準備,所以它不會使用:限制,一切工作正常。