Hello,
I am facing difficulties to generate subcategories in <UL> list.
I have a table with Menu Items :
cat_id | parent_id | title
-------------------------
1 | 0 | Solutions
2 | 0 | Products
3 | 1 | Web
4 | 1 | Development
5 | 2 | Softies
6 | 2 | PHP Book
-------------------------
I want to list get the out put in the form as below :
Solutions
Web
Development
Products
Softies
PHP Book
What i have written is :
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;
}
Could you please help me how to retrieve sub categories and get the output in :
<ul>
<li>
<ul>
</ul>
</li>
</ul>
Kindly suggest me how to go about..
Thanks and Rgds,
Pradeep
Edited by: KINO on Sep 14, 2008 4:53 PM