I'm doing pretty much the same thing on two different pages. It works as it should on one page and doesn't on the other. The two pages are pulling from different tables but everything else is the same. I'm hoping someone can see what I'm doing wrong here.
I'll explain the working page first... it is querying two tables to get a list of downloadable files, and the goal is to group them into their respective categories.
One table is Downloads, which has the following fields: id, cat_id, title, location, file_name, date_uploaded, downloads
The other table is Download_categories, whith the following fields: cat_id, category
Here's the query:
qDloads.Source = "SELECT a.title, a.location, a.file_name, (select b.category from download_categories b where b.cat_id = a.cat_id) as category FROM downloads a ORDER BY a.title"
And here's the code to output and group the results:
This works great. It outputs each category only once and displays the appropriate files under their appropriate category. You can see it at a free server it is residing on now:
The second page, the one that doesn't work, outputs all of the results, but doesn't properly group them. It outputs each category more than once and doesn't group the files as it should. You can see this one here:
I litterally copied the code from the working downloads page to create this page and just changed the code where appropriate. Here's the setup for this page.
The News table has the following fields: id, date_entered, cat_id, title, description
The News_categories table has the following fields: cat_id, news_cat
Here's the query:
qNews.Source = "SELECT a.id, a.title, a.date_entered, (select b.news_cat from news_categories b where b.cat_id = a.cat_id) as category FROM news a"
And here's the code to output and group the results:
Can anyone see why this page would not propery group the output? Thanks for any help!
I'll explain the working page first... it is querying two tables to get a list of downloadable files, and the goal is to group them into their respective categories.
One table is Downloads, which has the following fields: id, cat_id, title, location, file_name, date_uploaded, downloads
The other table is Download_categories, whith the following fields: cat_id, category
Here's the query:
qDloads.Source = "SELECT a.title, a.location, a.file_name, (select b.category from download_categories b where b.cat_id = a.cat_id) as category FROM downloads a ORDER BY a.title"
And here's the code to output and group the results:
Code:
<% While ((Repeat1__numRows <> 0) AND (NOT qDloads.EOF)) %>
<% If strCat <> qDloads("category") Then
strCat = qDloads("category")
Response.Write "<h4 style='color:#336699;'>" & strCat & "</h4>"
End If
strTitle = qDloads("title")
strLoc = qDloads("location")
strFile = qDloads("file_name")
Response.Write "<li> <a href='" & strLoc & strFile & "'>" & strTitle & "</a><br>"
%>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
qDloads.MoveNext()
Wend
%>
The second page, the one that doesn't work, outputs all of the results, but doesn't properly group them. It outputs each category more than once and doesn't group the files as it should. You can see this one here:
I litterally copied the code from the working downloads page to create this page and just changed the code where appropriate. Here's the setup for this page.
The News table has the following fields: id, date_entered, cat_id, title, description
The News_categories table has the following fields: cat_id, news_cat
Here's the query:
qNews.Source = "SELECT a.id, a.title, a.date_entered, (select b.news_cat from news_categories b where b.cat_id = a.cat_id) as category FROM news a"
And here's the code to output and group the results:
Code:
<% While ((Repeat1__numRows <> 0) AND (NOT qNews.EOF)) %>
<% If strCat <> qNews("category") Then
strCat = qNews("category")
Response.Write "<h4 style='color:#336699;'>" & strCat & "</h4>"
End If
strTitle = qNews("title")
strID = qNews("id")
strDate = qNews("date_entered")
Response.Write "<a href='detail.asp?id=" & strID & "'> <img src='../assets/img/arrow_rgt.gif' width='9' height='5' border='0'></a> <a href='detail.asp?id=" & strID & "'><span class='news_items'>" & strTitle & "</span></a> (" & strDate & ")<br>"
%>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
qNews.MoveNext()
Wend
%>
Can anyone see why this page would not propery group the output? Thanks for any help!