php表:每行显示3个单元格 [英] php table: display 3 cells in each row
本文介绍了php表:每行显示3个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看着这里: 排列成表格,每行有5个单元格
但是我无法修改我的代码.
but I cannot adapt my code..
我需要在表中显示PHP数组结果. 该表每行需要3个单元格.
I need to display PHP array results in a table. The table needs to have 3 cells for each row.
我不知道如何在每第3行输出<tr>
和</tr>
,并且在表包含许多记录而不是第一个记录的情况下,我也不知道如何输出最后一个</tr>
. 3的倍数.
I don't know how to output the <tr>
and </tr>
every 3rd row, and I don't know how to output the last </tr>
in case the table contains a number of records which is not a multiple of 3.
这是我的代码:
echo "<table>";
$num=mysql_numrows($result1);
$i=0;
while ($i < $num)
{
$aaa=mysql_result ($result1,$i,"aaa");
$bbb=mysql_result ($result1,$i,"bbb");
echo "
<td>$aaa $bbb</td> ";
$i++;
}
echo "</table>";
推荐答案
使用mod运算符%检查第三个元素.例如
use the mod operator % to check for the third element. e.g.
if($i%3 == 0) {
// this is the third element, start a new tr here
}
这篇关于php表:每行显示3个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文