Jump to content
xisto Community
Sign in to follow this  
mahesh2k

Displaying Rows & Columns Horizontaly

Recommended Posts

I'm experimenting with php and mysql. I have table in mySQL database something like: | sr.no| name | | 1 | abc | | 2 | xyz | | 3 | zxc |Now i see the table in vertical for serial number and name. But if i have to display them in horizontal way. How to do that ?like |sr no| 1 |2 |3 | 4| |name| abc|how to do this using php and mysql ?

Share this post


Link to post
Share on other sites

i want to display it on webpage. is it possible to display it that way ?

Yeah it is possible, even if it means looping through the same data twice. I don't practice much things with MySQL, so i can't provide any example source code, but i'm sure you have worked with other languages before, so you should be able to know what i mean by "looping through things twice."

Share this post


Link to post
Share on other sites

If I am thinking properly, this'll work, just mod it to your own database and mod the table configuration and whatnot. This uses L1 and L2 classes, which are alternating colors. You can do with it what you like. But, it NEEDS the "while" function.

<? if ($_GET[XX] == ""){  echo('<tr>	<td width=10% class=headersmall></td>	<td width=12% align=left class=headersmall>XX</td>	<td width=4% align=left class=headersmall></td>	<td width=11% align=left class=headersmall>XX</td>	<td width=14% align=left class=headersmall></td>		 </tr>');	  $result = mysql_query("SELECT * FROM `XX`");	$i = 0; 	while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {		if($line['id'] == '1'){$XX_name = XX; $XX= '1';}	   if($line['id'] == '2'){$XX_name = XX; $XX= '2';}		if($i%2 == 0) 	{ 	echo "<tr>	<td width=10% class=L1></td>	<td width=12% align=left class=L1>".$XX."</td>	<td width=4% align=left class=L1></td>	<td width=11% align=left class=L1><a class=link href=XX.php?tech=".$XX."'>XX</a></td>	<td width=14% align=left class=L1></td>		 </tr>"; 	$i++; 	} 	else 	{ 	echo "<tr>	<td width=10% class=L2></td>	<td width=12% align=left class=L2>".$XX."</td>	<td width=4% align=left class=L2></td>	<td width=11% align=left class=L2><a class=link href='XX.php?XX=".$techAbbr."'>XX</a></td>	<td width=14% align=left class=L2></td>		 </tr>"; 	$i++; 	} 	}   	}?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.