Connecting Tech Pros Worldwide Help | Site Map

Display Catagories into Subcategories from database ?

Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#1: Nov 9 '07
Hi every one any body can help me in this regards ? i don't know how to do that
how do i convert following code into sub catagory ?
like . . .
Expand|Select|Wrap|Line Numbers
  1. Computer
  2.     Mainboards
  3.     Keyboards
  4.     Mouse
  5. Process
  6.     Intel
  7.     AMD
  8.  
these catagories i've got in database
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Dim Conn, rsCatalog
  3.     Set Conn = Server.CreateObject("ADODB.Connection")
  4.     Conn.Open ConString
  5.     Set rsCatalog = Conn.Execute("SELECT * FROM catalogs")
  6.         While Not rsCatalog.EOF
  7.  
  8.     Response.Write rsCatalog("catalogID")
  9.         rsCatalog.MoveNext
  10.         Wend
  11.     rsCatalog.Close
  12.     Set rsCatalog = Nothing
  13. %>
  14.  
but when i display it's just like not with subcatagories ?
Expand|Select|Wrap|Line Numbers
  1. Computer
  2. Mainboards
  3. Keyboards
  4. Mouse
  5. Process
  6. Intel
  7. AMD
  8.  
but i want just main 2 catagories like Computer & Process then any body click on the Computer section then it's bring subcatagories ?
markrawlingson's Avatar
Moderator
 
Join Date: Aug 2007
Location: Bowmanville, Ontario
Posts: 329
#2: Nov 11 '07

re: Display Catagories into Subcategories from database ?


There are many ways to do something but the easiest would be to define whether the item is a top level item or a sub category item at a database level. In other words, Put a bit value in your database table. If it's top level item define a value of false, if it's a sub-level item define a value of true.

Then check the value as you loop through each record..

Expand|Select|Wrap|Line Numbers
  1. If rs("bSubCategory") = False Then 'Boolean value of false, it is a top level item, simply write it on the page
  2.    Response.Write rs("ID")
  3. Else 'Boolean value of true, it's a sub-level item, put a blockquote around it to indent it to visually show it's a sub-level item.
  4.    Response.Write "<blockquote>"
  5.    Response.Write rs("ID")
  6.    Response.Write "</blockquote>"
  7. End If
  8.  
Sincerely,
Mark
Expert
 
Join Date: Nov 2007
Posts: 126
#3: Nov 28 '07

re: Display Catagories into Subcategories from database ?


Please read a recent post of mine to my personal blog about programming:

Hierarchical Data Using SQL

It explains a common database table structure and some sample queries in regards to hierarchical data.
Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#4: Dec 26 '07

re: Display Catagories into Subcategories from database ?


Hi

i still not figer it out can you plz see my code & figer it out how the best way to find that

thaxxxxxxxxxxxxxxxxxxxxxx
Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#5: Jan 2 '08

re: Display Catagories into Subcategories from database ?


i still not figer it out can you plz see my code & figer it out how the best way to find that
Reply