This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Display records problem  RSS feed

 
michael yue
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I need to display some records in jsp in a specific order. I need to display it so that it can be grouped. Examples, my database records are below:

Name Age Brand
Jim 23 nokia
Al 25 nokia
Joe 37 motorola
May 24 nokia
Kim 29 samsung
Jon 22 motorola
Jac 22 motorola


I need to display in order by the brand in JSP page as below
Jim 23 nokia
Al 25 nokia
May 24 nokia

Display total records for nokia

Joe 37 motorola
Jon 22 motorola
Jac 22 motorola

Display total records for motorola

Kim 29 samsung

Display total records for samsung

How can I determine the time to split the record to display the total records for each group. Any advise? Thanks
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in your sql query just add

GROUP BY brand

it will work. enjoy

but one more thing i want you to do for me. just add siemens as well in your DB records. cuz i am loving it.
[ September 08, 2004: Message edited by: adeel ansari ]
 
Dicky Bullin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi lin,

Here's some code to implement grouping inside the JSP.
First you need the GROUP BY statement inside your SQL, just like what adeel said.

In case you want to group the Phone with adding some header or something before the member, here's some snippet.





Regards,


Dicky Bullin
[ September 09, 2004: Message edited by: Dicky Bullin ]
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use weasel ways with the SQL as illustrated below, but I'm not sure I'd recommend it. You choose:

I think that'll work. That way you can just iterate through your ResultSet as you would normally.

Jules
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my apologies GROUP BY doesn't work in this case. and wht Jules said is quite right. you will get the total no of records for a particular group after or before, not sure, a particular group list ends or starts. i think it is the best way if you really want a total no of records for a particular group. if not ORDER BY brand is OK and simple.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!