Click to See Complete Forum and Search --> : (sub)categories?


nwbee
06-05-2003, 11:53 AM
Hi,

I'm building an online menucard.

For this I'm using some asp code whis has a table for categories, this looks like:
CAT_ID -- CAT_name

I have another table for the details, this looks like:
ID -- PIC_CAT -- PIC_NAME --etc

PIC CAT is a number that corresponds with CAT_ID.

I have the page that shows all categories, with links to the details for that categorie.

But now I want to display them all in one page, ordered by category, like this:

Appetizers
app1
app2
app3

Main courses
mc1
mc2
mc3

Deserts
ds1
ds2
ds3

Can anyone show me how to do this?

cmelnick
06-06-2003, 10:44 AM
I am assuming your tables are from some database. Basically, you just need a nested loop to loop through the categories. Try something like this: (haven't tested this, so watch out for typing errors)


' Set these up however you normally do for your database connection
Dim dbConnection, rstCategories, rstItems
Set dbConnection = Server.CreateObject("ADODB.Connection")
Set rstCategories = Server.CreateObject("ADODB.Recordset")
Set rstItems = Server.CreateObject("ADODB.Recordset")

dbConnection.Open "Your connection string"

Dim txtCmd
txtCmd = "SELECT * FROM Categories"
rstCategories.Open txtCmd, dbConnection

Do Until rstCategories.EOF Or rstCategories.BOF
Response.Write rstCategories("CAT_name")
txtCmd = "SELECT * FROM Items WHERE PIC_CAT=" & rstCategories("CAT_ID")
rstItems.Open txtCmd, dbConnection

Do Until rstItems.EOF Or rstItems.BOF
Response.Write rstItems("PIC_NAME")
rstItems.MoveNext
Loop

rstCategories.MoveNext
Loop

nwbee
06-07-2003, 07:11 AM
That's great!
That works, thank you very much. :)

I still have one little problem.

When I write this:

<%
If rsPictures.Fields("PIC_DESC").Value <> "" Then
If intRowColor = 1 Then
Response.Write ("<TR class=""trborder""><td colspan=""3"" class=""klein"" height=""10"">test 1</td></tr>")
intRowColor = 1
Else
Response.Write ("<TR class=""trborder2""><td colspan=""3"" class=""klein"" height=""10"">test 2<td></tr>")
intRowColor = 0
End If
Else

End If
%>

it works fine, but when I write this:
<%
If rsPictures.Fields("PIC_DESC").Value <> "" Then
If intRowColor = 1 Then
Response.Write ("<TR class=""trborder""><td colspan=""3"" class=""klein"" height=""10"">" & rsPictures.Fields("PIC_DESC").Value & "</td></tr>")
intRowColor = 1
Else
Response.Write ("<TR class=""trborder2""><td colspan=""3"" class=""klein"" height=""10"">" & rsPictures.Fields("PIC_DESC").Value & "</td></tr>")
intRowColor = 0
End If
Else

End If
%>

the TR is showed, but, the field (PIC_DESC) isn't.