Results 1 to 5 of 5
- 09-14-2008, 08:01 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 9
- Rep Power
- 0
Generate <UL> list from Database with sub categories
Hello,
I am facing difficulties to generate subcategories in <UL> list.
I have a table with Menu Items :
Java Code:cat_id | parent_id | title ------------------------- 1 | 0 | Solutions 2 | 0 | Products 3 | 1 | Web 4 | 1 | Development 5 | 2 | Softies 6 | 2 | PHP Book -------------------------
Java Code:Solutions Web Development Products Softies PHP Book
Java Code:public String generateMenuHTML(String id1) throws SQLException { pdb = new Pdb(); String sql = "select ID,PARENT_ID,TITLE,URL,SORT,ICON from menu"; rset = pdb.executeQuery(sql); html = "<ul id='menu" + id1 + "'>"; while(rset.next()) { id = rset.getString("ID"); parent_id = rset.getString("PARENT_ID"); title = rset.getString("TITLE"); sort = rset.getString("SORT"); url = rset.getString("URL"); icon = rset.getString("ICON"); html = html + "<li id='it" + id + "'><a href='" + url + "'>" + title + "</a>"; if (parent_id.equalsIgnoreCase("1")) { System.out.println(parent_id); html = html +generateMenuHTML(id) ; } html = html + "</li>"; } html = html + "</ul>"; return html; }
<ul>
<li>
<ul>
</ul>
</li>
</ul>
Kindly suggest me how to go about..
Thanks and Rgds,
Pradeep
- 09-14-2008, 09:00 PM #2
Partial solution,.....
Java Code:public String generateMenuHTML(String id1) throws SQLException { StringBuffer html = new SringBuffer(); while(rset.next()) { html.append("<blockquote>"); html.append("<ul id=\""+ id1 +"\ >"); String cat_id = rset.getString("CATALOG_ID"); String parent_id = rset.getString("PARENT_ID"); String title = rset.getString("TITLE"); String sort = rset.getString("SORT"); String url = rset.getString("URL"); String icon = rset.getString("ICON"); // begin building string.... html.append("<li>" +cat_id+ "</li>");// html.append("<li>" +parent_id+ "</li>");// html.append("<li>" +sort+ "</li>");// html.append("<li>" +id+ "</li>");// html.append("</ul></blockquote>"); } // ......... return html.toString(); }
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 09-14-2008, 09:12 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 9
- Rep Power
- 0
Thanks for reply..
But for me to work.. output should be something like..
Java Code:<ul id='menu0'><li id='it1'><a href='SomeURL1'>Solution</a></li><li id='it2'><a href='SomeURL2'>712</a><ul><li id='it3'><a href='SomeURL3'>XX</a></ul></li></ul>
Thanks again..
Rgds,
Pradeep
- 09-14-2008, 09:40 PM #4
Can we make cat_id a file scope class ( default access ) on in some way put all the cat_id stuff in one place?
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 09-29-2008, 08:53 AM #5
Member
- Join Date
- Sep 2008
- Posts
- 9
- Rep Power
- 0
SOrry for delayed reply as i was sick.
coming aback to the problem - I am tryin to retrieve data in JSP as :
Java Code:<c:forEach var="section" items="${menu}"> <ul id="menu"> <li id="${section.id}"><a href="${section.url}">${section.title}</a> <ul id="section"> <c:forEach var="item" items="${section.menuItems}"> <li id="${item.id}"><a href="${item.url}">${item.title}</a></li> </c:forEach> </ul> </li> </ul> </c:forEach>
i see below display in JSP file :
Java Code:${section.title} ${item.title} ${section.title} ${section.title}
Similar Threads
-
How to generate primary key in EJB
By naresh_m in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 07-17-2008, 10:41 AM -
how to generate dynamic pdf
By valery in forum Advanced JavaReplies: 1Last Post: 08-06-2007, 11:01 PM -
how to generate xml with Dom4j
By leonard in forum XMLReplies: 1Last Post: 08-06-2007, 05:39 PM
Bookmarks