display the resultset of 2 table join
Hi,
I have 2 tables in my db category and subcategory
category tbl fields: catID CatName
subcategory tbl fields:subID CatID SubName
the two tables are joined through the common 'catID' field.
I want to display the records in 3 columns and in each column the category is shown +
its related subcategories.
like this:
Category1 Category2 category3
subCat1 subcat1 subcat1
subcat2 subcat2 subcat2
subcat3
I use the following code but it returns all the cats and subcats in a row.
How should I writer my sql query and the page code?
<%
Rs3.open "select * from category left outer join subcategory on subcategory.catid=category.catid",Conn,3,3
%>
<table width="430" cellpadding="2" cellspacing="2">
<%
Dim NumRows,Index
NumRows = -2
index = 0
rs_NumRows = rs_NumRows + NumRows
startrw = 0
endrw = index
numberOFColumns =4
numrows = -1
while((numrows <> 0) AND (Not rs3.EOF))
startrw = endrw + 1
endrw = endrw + numberOFColumns
num=num+1
while ((startrw <= endrw) AND (Not rs3.EOF))
%>
<td>
<table width="80" border="0" cellpadding="0" cellspacing="3" class="text">
<tr>
<td><p align="center">
<img src="images/<%=rs3("image")%>" width="61" height="46"></td>
</tr>
<tr>
<td><p align="center"><a href="show.asp?catid=<%=rs3("catid")%>"><%=rs3("ca tname")%>(<%'=rs3("card_count")%>)</a><a href="show.asp?catid=<%=rs3("catid")%>&subid=<%=rs 3("subid")%>"><%=rs3("subname")%></a></p></td>
</tr>
</table>
</td>
<%
startrw = startrw + 1
rs3.movenext
wend
%>
</tr>
<%
numrows=numrows-1
Wend
%>
</table></td>
|