我的前轮有个小问题。它循环遍历表,但只显示对应表中的第一个条目。之后,所有条目都在表之外。我希望它们出现在表中,我猜想这与SELECT语句有关。但我不确定。你能告诉我为什么这些条目不在表上吗?
显示条目

代码片段
<?php
//Beginn of PHP
if(isset($_POST['but_show'])){
$show_id = $_POST['showid'];
//prepare statement for MySQL injection
$queryResults = $wpdb->prepare( "SELECT id, fileurl, fk_verfuegungsberechtigter FROM dateien_vermieter WHERE fk_verfuegungsberechtigter = '$show_id'" );
$results = $wpdb->get_results( $queryResults );
//loop through data
//$name = $print->gemeinde;
?>
<table class='wp-list-table widefat striped'>
<thead>
<tr> <!-- display table header for edit button -->
<th style='text-align:center;' width=<?php $width[0]?>>ID</th>
<th style='text-align:center;' width=<?php $width[0]?>>Dateien</th>
<th style='text-align:center;' width=<?php $width[0]?>>Vermieter-ID</th>
</tr>
</thead>
<?php
foreach($results as $print) {
echo "
<tbody>
<tr> <!-- display table data for edit button use of above mentioned loop only change !!!!->name -->
<td style='text-align:center;' width=" . $width[0] . ">$print->id</td>
<td style='text-align:center;' width=" . $width[7] . "><a href='$print->fileurl'><button id='files' type='button'><i class='far fa-file'></i></button></a></td>
<td style='text-align:center;' width=" . $width[0] . ">$print->fk_verfuegungsberechtigter</td>
</tr>
</tbody>
</table>";
}
}
//End of PHP
?>发布于 2021-04-26 16:24:45
你把</tbody></table>锁在前额。试试下面的代码。
<?php if(isset($_POST['but_show'])){
$show_id = $_POST['showid'];
//prepare statement for MySQL injection
$queryResults = $wpdb->prepare( "SELECT id, fileurl, fk_verfuegungsberechtigter FROM dateien_vermieter WHERE fk_verfuegungsberechtigter = '$show_id'" );
$results = $wpdb->get_results( $queryResults );
//loop through data
//$name = $print->gemeinde;
?>
<table class='wp-list-table widefat striped'>
<thead>
<tr> <!-- display table header for edit button -->
<th style='text-align:center;' width=<?php $width[0]?>>ID</th>
<th style='text-align:center;' width=<?php $width[0]?>>Dateien</th>
<th style='text-align:center;' width=<?php $width[0]?>>Vermieter-ID</th>
</tr>
</thead>
<tbody>
<?php foreach($results as $print) { ?>
<tr> <!-- display table data for edit button use of above mentioned loop only change !!!!->name -->
<td style='text-align:center;' width="<?php echo $width[0]; ?>"><?php echo $print->id; ?></td>
<td style='text-align:center;' width="<?php echo $width[7]; ?>"><a href="<?php echo $print->fileurl; ?>"><button id='files' type='button'><i class='far fa-file'></i></button></a></td>
<td style='text-align:center;' width="<?php echo $width[0]; ?>"><?php echo $print->fk_verfuegungsberechtigter; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>或
<?php
//Beginn of PHP
if(isset($_POST['but_show'])){
$show_id = $_POST['showid'];
//prepare statement for MySQL injection
$queryResults = $wpdb->prepare( "SELECT id, fileurl, fk_verfuegungsberechtigter FROM dateien_vermieter WHERE fk_verfuegungsberechtigter = '$show_id'" );
$results = $wpdb->get_results( $queryResults );
//loop through data
//$name = $print->gemeinde;
?>
<table class='wp-list-table widefat striped'>
<thead>
<tr> <!-- display table header for edit button -->
<th style='text-align:center;' width=<?php $width[0]?>>ID</th>
<th style='text-align:center;' width=<?php $width[0]?>>Dateien</th>
<th style='text-align:center;' width=<?php $width[0]?>>Vermieter-ID</th>
</tr>
</thead>
<tbody>
<?php foreach($results as $print) {
echo "
<tr> <!-- display table data for edit button use of above mentioned loop only change !!!!->name -->
<td style='text-align:center;' width=" . $width[0] . ">$print->id</td>
<td style='text-align:center;' width=" . $width[7] . "><a href='$print->fileurl'><button id='files' type='button'><i class='far fa-file'></i></button></a></td>
<td style='text-align:center;' width=" . $width[0] . ">$print->fk_verfuegungsberechtigter</td>
</tr>";
} ?>
</tbody>
</table>
<?php } ?>https://stackoverflow.com/questions/67270162
复制相似问题