我试图用while循环来放一些带有文本的缩略图,但只有第一个<tr>
工作正常,第二个甚至没有显示。我没有得到错误,所以我不知道我做错了什么。
<?php
require_once("inc/config.inc.php");
$sql = "SELECT * FROM games ORDER BY RAND() LIMIT 20";
$result = $mysqli->query($sql);
$row = $result->fetch_assoc();
$counter = 0;
$max = 5;
$counter2 = 0;
$max2 = 5;
?>
<table style="table-layout:fixed;width:100%;text-align:center;" align="center" valign="center">
<?php
echo "<tr>";
while (($row = $result->fetch_assoc()) and ($counter < $max)) {echo "<td><a class='nogame' href='play.php?g=". $row['pid'] ."'><img src='". $tpath . $row['thumb'] ."'><br>". $row['name'] ."</a></td>";$counter++;}
echo "</tr>";
echo "<tr>";
while (($row = $result->fetch_assoc()) and ($counter2 < $max2)) {echo "<td><a class='nogame' href='play.php?g=". $row['pid'] ."'><img src='". $tpath . $row['thumb'] ."'><br>". $row['name'] ."</a></td>";$counter2++;}
echo "</tr>";
?>
</table>
我希望你能帮助我。抱歉,如果我犯了一个愚蠢的错误。我是PHP新手。我也试着用谷歌搜索,但是没有用。
问候
这里没有明显的问题可能导致你的问题。可能是数据库中的记录少于6条(6条,因为您在第5行"吃掉"了其中一条)。另外,请查看页面源中是否存在第二对tr-s。否则,你的代码会因为某些原因而死亡。