tags:

views:

41

answers:

1
    $db = mysql_connect("", "", "") or die("Could not connect.");
mysql_select_db("",$db)or die(mysql_error()); 
$sql = "SELECT * FROM table where 1";
$pager = new pager($sql,'page',6);
while($row = mysql_fetch_array($pager->result))
{
    echo $row['persons']."<br>";
}
 mysql_close($db);

above code output :

Mathew
Thomas
John
Stewart
Watson
Kelvin

What I need is it should split inot multiple columns say:

Mathew   Stewart
Thomas   Watson
John   Kelvin

HOw do I do this??

A: 
$i = 0;
$columnCount = 2;
echo '<table>';
while($row = mysql_fetch_array($pager->result))
{
     $newRow = ( $i % $columnCount == 0 );
     if( $newRow ) {
        echo '<tr>';
     }
     echo '<td>' . $row['persons'] . '</td>';
     if( $newRow ) {  
        echo '</tr>';
     }
     $i++;
}
echo '</table>';
Jacob Relkin
great but how do I put it in a neat table??
mathew
ok fine I think I can manage that THank you verymuch
mathew
oops one more question if I need in three columns then??
mathew
@mathew, edited my answer. Please accept this answer if it's the correct one. People will not answer your questions on SO if your accept rate is 33%
Jacob Relkin
sorry I always forget the same...
mathew
doesn't work column if more than 2. it gives odd results!!!!
mathew