Home  >  Article  >  Backend Development  >  如何在Table中将数据摆放成每行N列的最佳方法_PHP

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

WBOY
WBOYOriginal
2016-06-01 12:38:19704browse

今天在写程序的时候遇到一个问题如何将从数据库中取出的数据按每行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
Previous article:第十一节重载[11]_PHPNext article:php编程命名规则_PHP