1

I want to output my sql rows on each side of a line, without breaking the line. Forexample the html/css code i would like to end up with is something like this:

<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>

Is there a way to output the sql rows in two diffrent divs?

Stan
  • 11
  • 1
  • Having that `id='line'` element inside a loop is not a good idea. – techfoobar Nov 10 '12 at 10:17
  • @techfoobar reason for not a good idea? – Mr. Alien Nov 10 '12 at 10:17
  • @Mr.Alien - obviously, the page will end up with multiple elements with `id='line'` - Some info here: http://stackoverflow.com/questions/192048/can-an-html-element-have-multiple-ids – techfoobar Nov 10 '12 at 10:20
  • Lol Techfoobar. Id's are used when you want them displayed more than once on a page.. you just can't merge multiple id's into one element (or well, yes you can, but it's not a good idea) – Stan Nov 10 '12 at 10:23
  • Classes are used if you want to display something more then once. That is some very basic html and css knowledge. – Mats Rietdijk Nov 10 '12 at 10:31
  • 1
    Seems the easy way would be to fetch all the query rows to an array, split up the array into two and then loop each array in each div. – air4x Nov 10 '12 at 10:34

2 Answers2

0

Just write two different queries or fetch all rows and put it in an array and filter them like this:

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

OR JUST USE THE $row as an array to filter }

print_r(array_filter($array, "odd"));
echo "Even:\n";
print_r(array_filter($array, "even"));
Sjaak Rusma
  • 1,424
  • 3
  • 23
  • 36
0

Try this code:

<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>
Lao
  • 168
  • 1
  • 8