Fetching mysql records to a html table using PHP(使用 PHP 将 mysql 记录获取到 html 表)
问题描述
我正在尝试将我的 mysql 记录提取到一个表中,每个单元格必须只有一个图像.
I am trying to fetch my mysql records into a table, each cell must have one image only.
问题是照片根据我需要填充每一行的数量重复了 5 次.
The problem is that the photo duplicated 5 times according to the number I need to fill each row.
这是我的代码:
<table width="%" border="1" bordercolor="#F7F7F7" align="center" cellspacing="10" cellpadding="5">
<tr>
<?
for($i=0;$i<=5;$i++)
{
echo "<td width=125 height=125><img width=125 height=125 src=images/".$info['photo'] ."></td>";
} }?>
</tr>
</table>
如何更正此代码以使每张照片为每个单元格提取一次?
How can I correct this code to make each photo fetched one time for each cell?
***** 编辑 *****
***** EDIT *****
我把while放到表格里面了,现在抓取没问题,但是还是在同一行抓取,我需要做点什么来停止抓取,直到我在同一行有5个单元格,然后继续抓取新行.
I put the while inside the table, and the fetching is okay now, but it still fetch in the same row, I need to make something to stop fetching until I have 5 cells in the same row, then continue to fetch in a new row.
<table width="%" border="1" bordercolor="#F7F7F7" align="center" cellspacing="10" cellpadding="5">
<tr>
<?
while($info = mysql_fetch_array( $data ))
{
?>
<td width=125 height=125 ><img width=125 height=125 src=images/<? echo ($info['photo']); ?>></td>
<? } ?>
</tr>
推荐答案
你没有在循环内改变 $info['photo'].这就是为什么你要重复五次同一张照片.
You're not changing $info['photo'] inside the loop. That's why you're echoing the same photo five times.
根据您的代码外观,您可以像这样修改您的代码:
Depending how your code looks like you can modify your code like this:
$result = mysql_query($your_query);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo("<td width="125" height="125"><img width="125" height="125" src=" images/". $row["photo"] ."></td>");
}
这篇关于使用 PHP 将 mysql 记录获取到 html 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 PHP 将 mysql 记录获取到 html 表
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
