Home >php教程 >php手册 >如何在Table中将数据摆放成每行N列的最佳方法

如何在Table中将数据摆放成每行N列的最佳方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 10:25:471709browse

今天在写程序的时候,遇到一个问题:如何将从数据库中取出的数据按每行2列的格式
显示出来。我联想到在此曾看到的一篇文章——“关于%的技巧”,不仅非常简单地解决了
问题,而还且将每行2列扩展到N列:

例如:$n为Integer
?>
......
$sql="select id,subject from new ";

ora_parse($cursor,$sql);
ora_exec($cursor);
$i=0;

while(ora_fetch($cursor))
{
$i++;
if ($i%$n==1)
{
echo ""
echo "".ora_getcolumn($cursor,1)."";
}
elseif ($i%$n==0)
{
echo "".ora_getcolumn($cursor,1)."";
echo "";
}
else
echo "".ora_getcolumn($cursor,1)."";
}
?>
......

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn