Question : PHP - display HTML table as inverted mysql table

Hi all,

I have a mysql table that has 10 columns and 2 rows.
I can easly create a PHP script which will create an HTML table and display the data as is.

What I want to do is invert the rows and columns when displayed in HTML - ie...the 2 row titles from mysql become the column headings and the 10 columns from mysql become the first cells in each row in the the HTML table....obviously the data in the other cells will still be displayed in the right cells.

Can anyone show me a code example for how to achieve this?

Answer : PHP - display HTML table as inverted mysql table

Try the following code

hope it helps
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
<?php

	$db=mysql_connect('localhost',"root","") or die('Could not connect !');
    mysql_select_db("TEST",$db) or die('Could not find the database');

$query="select * from TABLE where 1";
$result = mysql_query($query);
$i=0;
while($row=mysql_fetch_row($result)) $array[$i++]=$row;
echo "<table border=1>";
for ($x=0;$x<count($array[0]);$x++){
	echo"<tr>";
	for ($y=0;$y<count($array);$y++){
		echo"<td>".$array[$y][$x]."</td>";
	}
	echo"</tr>";
}
echo"</table>";

?>
Random Solutions  
 
programming4us programming4us