php-两个不同div中的循环输出?

php-两个不同div中的循环输出?,php,html,css,Php,Html,Css,我希望在不中断行的情况下,在行的每一侧输出sql行。 例如,我希望最终得到的html/css代码如下: <div id='container'> <div style='float:left;'> Even loops here.. </div> <div id='line' style='float:left;'> </div> <div style='float:right;'> Uneven

我希望在不中断行的情况下,在行的每一侧输出sql行。 例如,我希望最终得到的html/css代码如下:

<div id='container'>

 <div style='float:left;'>
   Even loops here..
 </div>

 <div id='line' style='float:left;'>
 </div>

 <div style='float:right;'>
   Uneven loops here..
 </div>

 <div style='clear:both;'></div>
</div>
$array = array();
while($row = mysql_fetch_array($results)){
    $array[] = $row['number'];

这里甚至循环。。
这里的环不均匀。。

有没有办法将sql行输出到两个不同的div中?

只需编写两个不同的查询或获取所有行并将其放入一个数组中,然后按如下方式过滤它们:

<div id='container'>

 <div style='float:left;'>
   Even loops here..
 </div>

 <div id='line' style='float:left;'>
 </div>

 <div style='float:right;'>
   Uneven loops here..
 </div>

 <div style='clear:both;'></div>
</div>
$array = array();
while($row = mysql_fetch_array($results)){
    $array[] = $row['number'];
或者只使用$row作为数组进行筛选 }

请尝试以下代码:

<div id='container'>

 <div style='float:left;'>
   <?php
   $ct_row = 0;
   foreach ($array as $one) :
   if (($ct_row % 2) == 0) {
        echo $one;
   }
   $ct_row++;
   endforeach;
   ?>
 </div>

 <div id='line' style='float:left;'>
 </div>

 <div style='float:right;'>
   <?php
   $ct_row = 0;
   foreach ($array as $one) :
   if (($ct_row % 2) != 0) {
        echo $one;
   }
   $ct_row++;
   endforeach;
   ?>
 </div>

 <div style='clear:both;'></div>
</div>


在循环中包含
id='line'
元素不是一个好主意。@techfoobar这不是一个好主意的原因?@Mr.Alien-很明显,页面将以多个元素结尾,并且
id='line'
-这里有一些信息:Lol techfoobar。当您希望在一页上多次显示Id时,将使用Id。。您不能将多个id合并到一个元素中(或者,您可以,但这不是一个好主意),似乎最简单的方法是将所有查询行提取到一个数组中,将数组拆分为两个,然后在每个div中循环每个数组。