Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. String sql = "select * from sections inner join subsections on sections.id_section=subsections.id_section ";
  2. ResultSet rs = s.executeQuery(sql);
  3. while (rs.next())
  4. {
  5. out.println("<div id='accordion-container'>" + "<h2 class='accordion-header'>" + rs.getString("section_name") + "</h2>");
  6. }
  7. while (rs.next()) {
  8. out.println("<div class='accordion-content'>" + rs.getString("subsection_name") + "</div>" + "</div>");
  9. }
  10. rs.close();
  11. s.close();
  12. con.close();
  13.  
  14. ResultSet srs = st.executeQuery("SELECT * FROM subsections inner join sections on subsections.id_section=sections.id_section");
  15.  
  16. //variables for current and previous section ids (initially 0 = non-existent)
  17. int idCurrentSection = 0;
  18. int idPreviousSection = 0;
  19.  
  20. while (srs.next()) {
  21. idCurrentSection = srs.getInt("id_section"); //get and save the current section id
  22. //if previous section is equal to current section we skip closing and opening a new section block and just write the subsection name
  23. if(idCurrentSection!=idPreviousSection){ //if current section is different from previous section we need to start a new section block
  24. if(idPreviousSection != 0) //if previous section id is different from 0 we need to close the previous section block
  25. System.out.println("</div>");
  26. System.out.println("<div class='section'>"); //open a new section block
  27. }
  28.  
  29.  
  30. System.out.println("<p>"+srs.getInt("section_name")+"</p>"); //write the new section name
  31.  
  32. System.out.println("<div class='subsection'>"); //start a new subsection
  33. System.out.println("<p>"+srs.getInt("subsection_name")+"</p>"); //write the subsection name
  34. System.out.println("</div>"); //inchid subsectiunea
  35.  
  36. idPreviousSection = idCurrentSection; //previous section is now the current section
  37.  
  38. }
  39.  
  40. System.out.println("</div>"); //careful to close the last section block
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement