如何在Table中将数据摆放成每行N列的最佳方法
时间:2007-02-17 来源:PHP爱好者
今天在写程序的时候,遇到一个问题:如何将从数据库中取出的数据按每行2列的格式
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
显示出来。我联想到在此曾看到的一篇文章——“关于%的技巧”,不仅非常简单地解决了
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
问题,而还且将每行2列扩展到N列:
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
例如:$n为Integer
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
?>
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
......
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
$sql="select id,subject from new ";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ora_parse($cursor,$sql);
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ora_exec($cursor);
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
$i=0;
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
while(ora_fetch($cursor))
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
{
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
$i++;
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
if ($i%$n==1)
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
{
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "<tr>"
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "<td>".ora_getcolumn($cursor,1)."</td>";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
}
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
elseif ($i%$n==0)
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
{
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "<td>".ora_getcolumn($cursor,1)."</td>";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "</tr>";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
}
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
else
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "<td>".ora_getcolumn($cursor,1)."</td>";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
}
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
?>
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
......
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDn
php爱好者 站 http://www.phpfans.net 网页制作|网站建设|数据采集.
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
显示出来。我联想到在此曾看到的一篇文章——“关于%的技巧”,不仅非常简单地解决了
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
问题,而还且将每行2列扩展到N列:
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
例如:$n为Integer
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
?>
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
......
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
$sql="select id,subject from new ";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ora_parse($cursor,$sql);
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ora_exec($cursor);
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
$i=0;
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
while(ora_fetch($cursor))
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
{
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
$i++;
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
if ($i%$n==1)
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
{
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "<tr>"
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "<td>".ora_getcolumn($cursor,1)."</td>";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
}
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
elseif ($i%$n==0)
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
{
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "<td>".ora_getcolumn($cursor,1)."</td>";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "</tr>";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
}
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
else
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
echo "<td>".ora_getcolumn($cursor,1)."</td>";
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
}
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
?>
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDnr
......
ww w.china it power.coN8V58kBkROkoCSqwsaMz9jDn
php爱好者 站 http://www.phpfans.net 网页制作|网站建设|数据采集.
相关阅读 更多 +