?
Solved

PHP - display HTML table as inverted mysql table

Posted on 2010-08-25
3
Medium Priority
?
328 Views
Last Modified: 2013-12-13
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?
0
Comment
Question by:amrox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
racmail2001 earned 2000 total points
ID: 33526644
Try the following code

hope it helps
<?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>";

?>

Open in new window

0
 
LVL 4

Author Closing Comment

by:amrox
ID: 33529382
fantastic, exactly what I needed, worked out of the box (so to speak), thanks very much
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question