Jump to content

Sort Entries Into Columns


HighCaliber

Recommended Posts

I am creating my own game script and I would like to sort my MySQL results for my all games page into two columns. I would like it to show the first half of the entries in column 1 and the second half in column 2.For example...

<table><tr><td>Entry 1</td><td>Entry 4</td></tr><tr><td>Entry 2</td><td>Entry 5</td></tr><tr><td>Entry 3</td><td>Entry 6</td></tr></table>

Does anyone know how to make it sort entries this way?

Link to post
Share on other sites

use a for loop with an if/else in side of it...so like:

$ne = 6;$count = count($ne);$size = $count/2;for($i=0; $i<$size; $i++){ if($i % 2) {  $number = $i;  print "<tr><td>Entry $number</td>"; } else{  $number = $i +$size;  print "<td>Entry $number</td></tr>"; }}

that will printEntry 1 Entry 4Entry 2 Entry 5Entry 3 Entry 6just to give you some help in the right direction...

Link to post
Share on other sites

$count = count($ne);What's this for?My proposal:

<table><?php$ne = 5;$size = ceil($ne/2);for($i=1; $i<=$size; $i++){  $number = $i;  print "<tr><td>Entry $number</td>";  $number = $i +$size;  if ($number <= $ne)  print "<td>Entry $number</td></tr>";  else  print "<td> </td></tr>";}?></table>

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...