使用PHP获取mysql记录到一个html表格 [英] Fetching mysql records to a html table using PHP
问题描述
问题在于照片复制了5次,根据数字我需要填写每一行。
这是我的代码:
< table width =%border =1bordercolor =#F7F7F7align =centercellspacing =10cellpadding =5>
< tr>
<? ($ i = 0; $ i <= 5; $ i ++)
{
echo $< td width = 125>>< img width = 125 height = 125 src = images /\".$ info ['photo']。>< / td>;
}}?>
< / tr>
< / table>
如何纠正这段代码,
*****编辑*****
我把桌子放进桌子里,现在,但它仍然在同一行中获取,我需要做一些事情来停止获取,直到我有5个单元格在同一行,然后继续获取一个新的行。
<表宽度= % BORDER = 1 BORDERCOLOR = #F7F7F7 ALIGN = 中心 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'] 在循环中。这就是为什么你回应相同的照片五次。
取决于你的代码如何看起来像你可以修改你的代码是这样的:
$ result = mysql_query($ your_query);
而($行= mysql_fetch_array($结果,MYSQL_NUM)){
回波( < TD宽度= \ 125\高度= \ 125\ >< img width = \125 \height = \125 \src = \images /。$ row [photo]。>< / td>) ;
}
I am trying to fetch my mysql records into a table, each cell must have one image only.
The problem is that the photo duplicated 5 times according to the number I need to fill each row.
Here is my code:
<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 *****
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>
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屋!