我正在显示存储在我的数据库中的图像。
见下面的代码
$num_rows = mysql_num_rows($result41);
for ($i = 1; $i <= mysql_num_rows($result41); $i++)
{
$row = mysql_fetch_array($result41);
$upload_id = $row ['upload_id'];
$file = $row ['FILE_NAME'];
echo"
<td>
<a href='image.php?id=$upload_id&gallery=$id'><center>
<img src='uploads/$file' alt='$name Gallery' title='$name Album' class='resize'>
</td>";
}
if ($i % 0 == 4) {
echo '</tr>'; // it's time to move to next row
}
我的问题是,在显示 4 列后如何移动到另一行? (每行仅 4 张图像)
我的脚本中有
if ($i % 0 == 4)
但似乎不起作用?谢谢
最佳答案
像这样 :
for ($i = 1; $i <= mysql_num_rows($result41); $i++)
{
$row = mysql_fetch_array($result41);
$upload_id = $row ['upload_id'];
$file = $row ['FILE_NAME'];
if($i % 4 == 0) echo "<tr>";
echo"
<td>
<a href='image.php?id=$upload_id&gallery=$id'><center>
<img src='uploads/$file' alt='$name Gallery' title='$name Album' class='resize'>
</td>";
if($i % 4 == 3) echo "</tr>";
}
并查看
PHP PDO
以了解您对 Google 的 Mysql 访问;)并从 0 开始循环(for)?
关于PHP 显示数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32605574/