2016-09-06 4 views
-5

Ich programmiere meine erste Seite mit php und mysql. Jetzt bin ich auf einen Fehler gestoßen, den ich selbst nicht lösen kann. Wenn man sich das Bild ansieht, sind die ersten drei Spalten case1, die nächste case2 und die letzte case3. Jetzt ist mein Problem, dass nur die erste und letzte Tabelle korrekt angezeigt wurden. In der zweiten und dritten Tabelle fehlt die Spalte "Entfernung". Die vierte Tabelle ist komplett durcheinander.php MySQL - gemischte Ausgabe

Hoffentlich konnten Sie meinen Fehler aufzeigen. Danke im Voraus.

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

Kein Weg, ich durchkämmen so viel Code ... können Sie es eingrenzen? Haben Sie Ihr Fehlerprotokoll überprüft? –

+0

Ihre beste Hoffnung auf das Debuggen ist es, ein wirklich kleines Beispiel zu erstellen. Was passiert zum Beispiel, wenn Sie alle bis auf die zweite Tabelle und alle außer der Spalte distanz in dieser Tabelle vollständig entfernen. –

+0

Es gibt keine 'distanz' in' $ statement_infoart_2' oder '$ statement_infoart_3'. Warum sollte das in diesen Fällen sein? – Barmar

Antwort

0

Sie wissen nicht genau, warum, aber nachdem ich emuliert Switched bereitet wieder auf und änderte die Vorbereitung, so dass es nicht nutzen: Limit, alles funktioniert.