Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Displaying Rows & Columns Horizontaly


5 replies to this topic

#1 mahesh2k

    Trap Double Mocha Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Valley of Darkness
  • myCENT:27.17
  • Spam Patrol

Posted 07 February 2010 - 11:10 AM

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 ?

#2 Baniboy

    Advocatus Diaboli

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 878 posts
  • Gender:Male
  • Location:/root
  • Interests:Everything...
  • myCENT:37.47

Posted 07 February 2010 - 02:20 PM

You want to display them horizontally in the MySQL database or in a web page?

#3 mahesh2k

    Trap Double Mocha Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Valley of Darkness
  • myCENT:27.17
  • Spam Patrol

Posted 07 February 2010 - 04:50 PM

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

#4 truefusion

    Coincidence is non-sequitur, therefore everything has a reason for its existence (except if they are eternal).

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,216 posts
  • Gender:Male
  • Location:No, not there. Not there either. Yes, you'll never figure it out.
  • Interests:God, Christianity.
  • myCENT:86.16

Posted 07 February 2010 - 08:09 PM

View Postmahesh2k, on Feb 7 2010, 11:50 AM, said:

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."

#5 Semsem

    Member [Level 2]

  • Kontributors
  • PipPipPipPipPip
  • 84 posts
  • Gender:Male
  • myCENT:10.78

Posted 08 February 2010 - 03:16 AM

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++; 
	} 
	}   
	}?>


#6 mahesh2k

    Trap Double Mocha Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Valley of Darkness
  • myCENT:27.17
  • Spam Patrol

Posted 08 February 2010 - 08:13 AM

Thanks TF and semsem. Going to try this one, will keep you posted.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users