How to put an array into columns

    $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
Stuart
Watson
Kelvin

I need it to break into multiple columns:

Matthew Stewart
Thomas Watson
John Kelvin

HOw am I doing this ??

+2


a source to share


1 answer


$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>';

      



0


a source







All Articles