Displaying rows of data as collumns?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all

Does anyone know of an efficient way to retreive data from a mysql db
and display the record rows as collumns?

I have been doing this:
<display headers>
<while ($row = mysql_fetch_array($result)) { >
<display row 1 of result>
<display row 2... } >
<end table>

but I want to do this instead:
<col 1 header > <row 1 col 1> <row 2 col1> <row3 col1>
<col 2 header> <row 1 col 2> <row 2 col2> <row3 col2>
<col 3 header> <row 1 col 3> <row 2 col3> <row3 col3>

any ideas?

Re: Displaying rows of data as collumns?

Quoted text here. Click to load it

You're probably best off putting each record row in an array, so you'd get
something like:

while ($row = mysql_fetch_array($result))
  $rows[] = $row;

That way, you'll have access to all the results before you start drawing
your table. Then for each row of the table you print out, you can loop
through the array printing out the appropriate column of SQL output.

foreach ($rows as $row)
  echo "<td></td>";

Perhaps something like that might work?

Hope that helps,

Site Timeline