php MySQL - 混合输出

时间:2016-09-06 19:13:40

标签: php mysql html-table

我用php和mysql编写我的第一页。现在我遇到了一个我无法自己解决的错误。如果看图片,前三列是case1,下一列是case2,最后一列是case3。 现在我的问题是,只有第一个和最后一个表显示正确。第二和第三张表缺少" Distanz"柱。第四张表完全混淆了。

希望你能指出我的错误。提前谢谢。

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   
?>

1 个答案:

答案 0 :(得分:0)

不知道究竟为什么,但在我切换模拟后准备好并改变准备,以便它不会使用:限制,一切正常。