I\'m attempting to retrieve all that data from a database, put it in a table (more than one table if necessary) and display them column-wise in lots of 4 split across multip
There's not enough information here to say whether or not you should be using a table because you provided non-data.
If we're writing a closet organization application, our data might come out of the database like this:
John | Shoes | 3
John | Pants | 10
Sally | Shoes | 12
Sally | Pants | 8
Billy | Shoes | 4
Billy | Pants | 9
Kate | Shoes | 6
Kate | Pants | 6
But we want to display it like this:
Member | Shoes | Pants
John | 3 | 10
Sally | 12 | 8
Billy | 4 | 9
Kate | 6 | 6
We would write our loop something like this:
$last = null;
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
if ($last != $row['member']) {
if ($last) { // $last is null on our first pass through the loop, so don't print the tr's
?>
}
?>
=$row['member']?>
$last = $row['member'];
}
?>
=$row['quantity']?>
}
?>
The headers? Well, typically I would recommend looping twice and resetting the pointer, but I don't see the equivalent of mysql_data_seek
or pg_result_seek
for the interface you're using, so I can't help you any farther than this. Using output buffering on the first "row" of results combined with a collector variable gathering up all of the headers as an array can work without the need to reset the pointer.
If you're just wanting to spit out the results in 4 columns because you think it looks prettier and not because it expresses tabular data, using CSS columns would be the better way to go.