【发布时间】:2016-04-07 00:30:26
【问题描述】:
我有一个数组,其中包含许多不同图像的 URL。
我的目标是输出数组中的前 7 个图像,创建一个新行,输出接下来的 7 个图像,创建一个新行,然后继续执行此操作,直到数组中没有更多 URL。
当前代码
<?php
$command = 'select * from products;';//The command to be executed
$result = mysqli_query($con, $command); //The result of the command
if (mysqli_num_rows($result) > 0)
{
// output data of each row
echo "<table align='center'>";
$images = array();
$name = array();
while($row = mysqli_fetch_assoc($result)) //Store all product images and their names in two SEPERATE arrays
{
$images[] = $row['Image'];
$names[] = $row['Name'];
}
for($x = 0; $x < 1; $x++)
{
echo "<tr>";
foreach($images as $image)
{
echo "<td> <img src='" . $image . "' height='80' width='100'/></td>";
}
echo "</tr>";
}
}
?>
目前,此代码水平输出 $images[] 数组中的所有图像,但在显示前七张图像后不会创建新行。
我将图像放在一个表格中,以便输出均匀分布。
有人可以为我指明正确的方向以获得我想要的输出吗?我环顾四周并尝试了几种解决方案,但我没有进一步前进。
【问题讨论】:
-
我可以破坏你的代码来构建新代码吗?
-
@FrayneKonok 当然。
-
查看答案。