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 multiple pages.
I would like to know how I would get the tables to display horizontally e.g.
Table Header Table Header Table Header
Table Data Table Data Table Data
Table Data Table Data Table Data
Rather than:
Table Header
Table Data
Table Data
Table Header
Table Data etc.
Here is the code so far:
// While loop that will display the results in groups of 4
while($row=sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC))
{ $newDate = $row['datenow']->format('d/m/Y'); ?>
<table id="syncresults">
<thead>
<tr>
<th scope="col" id="dateheader"> <?php echo $newDate ?></th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $row['nbsactive']; ?></td>
</tr>
<tr>
<td><?php echo $row['nbsmanysynced']; ?></td>
</tr>
<tr>
<td><?php echo $row['nbsthreedays']; ?></td>
</tr>
</tbody>
Any suggestions on how to do this or to point me in the right direction would be greatly appreciated.
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:
But we want to display it like this:
We would write our loop something like this:
The headers? Well, typically I would recommend looping twice and resetting the pointer, but I don’t see the equivalent of
mysql_data_seekorpg_result_seekfor 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.