【发布时间】:2017-01-14 08:10:00
【问题描述】:
我正在使用 php 和 mysql 编写我的第一页。现在我遇到了一个我自己无法解决的错误。如果看图片,前三列是case1,接下来是case2,最后是case3。 现在我的问题是,只有第一个和最后一个表显示正确。第二个和第三个表缺少“Distanz”列。第四张桌子完全混淆了。
希望你能指出我的错误。提前致谢。
<?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
?>
【问题讨论】:
-
我不可能梳理这么多代码...你能缩小范围吗?你检查过你的错误日志吗?
-
调试这个的最大希望是尝试创建一个非常小的示例。例如,如果您完全删除除第二个表之外的所有表,以及该表中除 distanz 列之外的所有列。
-
$statement_infoart_2或$statement_infoart_3中没有distanz。为什么会出现这种情况? -
检查 5,6 行:你还没有定义 distanz
-
Distanz列没有丢失。case 2或case 3中没有任何内容表示要打印具有该名称的列。
标签: php mysql html-table