将php echo行分为3列

时间:2015-04-13 14:56:47

标签: php html css

如何从1个SQL表中获取数据库项并使用php将它们分成3个单独的列(html div)

1 个答案:

答案 0 :(得分:0)

这是一个小例子:

<?php

$result=array('one','two','three','four','five','six','seven','eight','nine','ten');
$colon=3;//how much div
$divid=ceil(count($result)/$colon);//how much per div

for($x=0;$x<count($result);$x++){
  if($x%$divid!=0){ 
    echo ' '.$result[$x];
   }else{ 
    echo ($x==0)? '<div>'.$result[$x]:'</div><div>'.$result[$x];
   }  
}
echo '</div>';

?>
相关问题