使用 PHP 将 mysql 记录获取到 html 表 [英] Fetching mysql records to a html table using PHP

查看:30
本文介绍了使用 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 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆