Forum Moderators: coopster

Message Too Old, No Replies

formatting table and fetching correct results using php

         

varunkrish

3:49 am on Jul 10, 2005 (gmt 0)

10+ Year Member



I want to build a table for displaying the results from a mysql table in the following format
col1,col2,col3,col4,col5 are columns in the mysql table
rows 1 to 5 are the rows fetched from the table
<table width="100" border="0" cellspacing="2" cellpadding="2">
<tr>
<td><strong>col1</strong></td>
<td>row1.col1</td>
<td>row2.col1</td>
<td>row3.col1</td>
<td>row4.col1</td>
<td>row5.col1</td>
</tr>
<tr>
<td><strong>col2</strong></td>
<td>row1.col2</td>
<td>row2.col2</td>
<td>row3.col2</td>
<td>row4.col2</td>
<td>row5.col2</td>
</tr>
<tr>
<td><strong>col3</strong></td>
<td>row1.col3</td>
<td>row2.col3</td>
<td>row3.col3</td>
<td>row4.col3</td>
<td>row5.col3</td>
</tr>
<tr>
<td><strong>col4</strong></td>
<td>row1.col4</td>
<td>row2.col4</td>
<td>row3.col4</td>
<td>row4.col4</td>
<td>row5.col4</td>
</tr>
<tr>
<td><strong>col5</strong></td>
<td>row1.col5</td>
<td>row2.col5</td>
<td>row3.col5</td>
<td>row4.col5</td>
<td>row5.col5</td>
</tr>
</table>

please help me on how to start doing this

jatar_k

4:21 am on Jul 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think the best way to do this is to load your results into an array and then display your output in a seperate loop.

$results = array();
while($row = mysql_fetch_array($query)) {
$result[] = array($row[0],$row[1],$row[2],$row[3],$row[4]);
}

then you could use a foreach or a while to run through the array and output your results.