php MySQL - 混合输出

php MySQL - 混合输出

问题描述:

我正在用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

不知道为什么,但在我交换仿真准备重新开启,改变了准备,所以它不会使用:限制,一切工作正常。