使用3x3的布局进行分页时遇到问题 这是我的while循环,尝试了几个分页,但太复杂了
while($row = mysqli_fetch_array($result)){
$id = $row['id'];
$name = $row['name'];
$picture = $row['picture'];
$rowPic = "<td><a href='dologinuser.php?id=$id'>";
$rowPic .= "<img width='200px' height='133px' src='images/$picture' />";
$rowPic .= "</a><br/>";
$rowPic .= "<strong>$name</strong>";
echo $rowPic;
$split++;
if ($split%3==0){
echo '</tr><tr>';
答案 0 :(得分:0)
做这样的事情怎么样?我相信这种方式更具可读性。
<?php
// Grouping the code into table-like array
$count = 0;
while($row = mysqli_fetch_array($result)) {
$table[$count / 3][$count % 3] = $row;
$count++;
}
// Constructing HTML code
$html = "<table>";
foreach($table as $row) {
$html .= "<tr>";
foreach($row as $col) {
$id = $col['id'];
$html .= "<td>" . "whatever you want to put" . "</td>";
}
$html .= "</tr>";
}
$html .= "</table>";
?>