This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a HTML table to display values from a database

 
Sridhar Venkataraman
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a database where I need to display as many rows in a HTML table as the maximum value in one of the columns in the corresponding table in a database.

For example, consider this bunch of data stored in the database:

1 | 1 | abc
1 | 2 | def
1 | 3 | ghi
2 | 1 | jkl
2 | 2 | mno
2 | 3 | pqr

Now, I need to create two rows (because the maximum value in the first column is 2) in the HTML table where I want to display this data. However, for every row which has the value 1 or 2, I need to create three columns (because there are three entries with the values 1 and 2 in the first column).

So the result (i.e. HTML table) rendered on the JSP page should be something like (consider that I'm displaying the last column):

abc | def | ghi
jkl | mno | pqr


How do I implement this in JSP, considering that I'm following an MVC architecture (no special frameworks like Struts and the like though)?

Thanks all for your inputs.

[ January 08, 2008: Message edited by: Sridhar Venkataraman ]

[ January 08, 2008: Message edited by: David O'Meara ]
[ January 08, 2008: Message edited by: Bear Bibeault ]
 
Pras Tiwari
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering this is your database table:-

1 | 1 | abc
1 | 2 | def
1 | 3 | ghi
2 | 1 | jkl
2 | 2 | mno
2 | 3 | pqr

Could you please mention/draw here the layout to be displayed in web page (2rows & 3 columns with above data) also? Because I am not sure what you want to be displayed exactly.
 
Sridhar Venkataraman
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the result (i.e. HTML table) rendered on the JSP page should be something like (consider that I'm displaying the last column):

abc | def | ghi
jkl | mno | pqr

Here...I had this in my first post.

Basically this comes from the fact that the first column has two distinct numnbers (1 and 2), and there are three instances where these numbers appear in the first column. So I need the output to display all the rows which have a value of 1,2....and so on in the same row on the HTML table.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please EaseUp.

Dave
 
Sridhar Venkataraman
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies...it's kind of a bad habit that I have
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic