OK...
The only trick to this is to keep track of how many columns(cells) of data you have written out, start a new row when you have reached the desired number of columns, and then make sure to pad the last row with enough empty cells to meet your row quota (to balance the table).
EXAMPLE:
// start table
print "<TABLE><TR>";
$sql = "select name from users";
if ($result = pg_exec($conn, $sql)) {
$colsPerRow=3; // how many cols we want
$colTracker=0; // keep track of 'em
$dataIdx = 0;
while ($data = @pg_fetch_object($result, $dataIdx):
// put out a column
print "<TD>" . $data->users_name . "</TD>";
$colTracker++; // increment tracker
// if we reached our desired number
// of columns, start a new row
if ($colTracker=$colsPerRow) {
print "</TR><TR>";
$colTracker=0; // reset
}
$dataIdx++;
} // end while loop
// before we can close the table
// we need to finish off the last row
// if we didn't fill it with data
while ($colTracker <= $colsPerRow) {
// output blank cell
print "<TD></TD>";
$colTracker++;
}
}
// now finish the table
print "</TR></TABLE>";
=========================
There may be some typos in there, but I think you can get the general idea.
-- Rich