1

我想在一行的每一侧输出我的 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>

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

4

2 回答 2

0

只需编写两个不同的查询或获取所有行并将其放入数组中并像这样过滤它们:

$array = array();
while($row = mysql_fetch_array($results)){
    $array[] = $row['number'];

或者只是使用 $row 作为一个数组来过滤 }

print_r(array_filter($array, "odd"));
echo "Even:\n";
print_r(array_filter($array, "even"));
于 2012-11-10T10:56:11.823 回答
0

试试这个代码:

<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>
于 2012-11-10T10:56:55.353 回答