使用 PHP 获取表中的照片
我正在尝试以这种方式获取我的 mysql 数据,每行 5 张照片,最多 2 行,这似乎不起作用,因为循环不断在我拥有的 2 行中重复照片。
这是我的代码:
<table border="1" width="%">
<?php
while($info = mysql_fetch_array( $data ))
{
for ($tr=1;$tr<=3;++$tr)
{
echo "<tr>";
for ($td=1;$td<=5;++$td)
{
echo "<td><img width=125 height=125 src=images/".($info['photo']). "></td>";
}
echo "</tr>" ;
}
}
?>
</table>
请帮我解决这个问题,结果一直处于这种状态:
I am trying to fetch my mysql data on this way, 5 photos each row, 2 rows max this seems doesn't work with as the loop keeps to duplicate photos in the 2 rows I have.
Here is my code :
<table border="1" width="%">
<?php
while($info = mysql_fetch_array( $data ))
{
for ($tr=1;$tr<=3;++$tr)
{
echo "<tr>";
for ($td=1;$td<=5;++$td)
{
echo "<td><img width=125 height=125 src=images/".($info['photo']). "></td>";
}
echo "</tr>" ;
}
}
?>
</table>
Please help me to solve this, the results keep coming in this status:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯...您的
while
循环会迭代所有照片。对于每张照片,由于for
循环,您会执行 3 * 5 次迭代。你实际上可能想做的是这样的:Well...your
while
loop iterates over all photos. For each photo you do 3 * 5 iterations due to yourfor
loops. What you actually might want to do is something like this:采用非常简单的方法..首先将获取的图像复制到一维数组中,然后将它们相应地放入表中
following a very easy approach .. first copy the fetched images into a single dimensional array and then place them into the table accordingly