Click to See Complete Forum and Search --> : One copy of each Category
mrmazur
07-04-2007, 11:53 AM
Here's my dilemma. I have a bunch of content items that are filed in my database under a specific month (one table). So I may have a 4 records for March, 3 for April, 1 for May, etc. One field in my table holds these Months. What I want to do is just get 1 instance of each month from my database without the months repeating because of the number of records for that month.
So instead of getting:
March
March
March
March
April
April
April
May
I need to have the output be more like:
March
April
May
Help!
Thanks,
mrmazur
07-04-2007, 03:02 PM
Ok, I figured out my solution to this dilema. Here's the code I used:
<%
dim compare1, compare2
Do While NOT rsEntries.EOF
compare1 = rsEntries("month") & rsEntries("year")
If NOT compare1 = compare2 Then
%>
<p class="nav" align="right">
<strong><a href="dynamic_demo.asp?nID=<% =rsEntries("month") & rsEntries("year") %>"><% =rsEntries("month") & " " & rsEntries("year") %></a></strong></p>
<%
compare2 = rsEntries("month") & rsEntries("year")
rsEntries.MoveNext
Else
compare2 = rsEntries("month") & rsEntries("year")
rsEntries.MoveNext
End If
Loop
%>
Basically I pulled the first record from my recordset and assigned it to compare1. Since initially the variable compare2 didn't hold any value the first condition was met (If NOT compare1 = compare2) and so it displayed the item I wanted on the screen. It then stored the value of that record in the variable compare2 then moved to the next record and looped. Then went through the process again. Any time it encounter a duplicate compare1 and compare2 it would simply store the info of the record in compare2 and once again loop.
I'm so glad I finally figured this out! What a pain in the ass it was though. I spent a few hours last night on this problem, and a few hours this morning. I hope this helps others out there encountering the same or similar problem.
Terrorke
07-05-2007, 05:00 AM
An easier way of doing is this is to use the distinct function in your SQL statement.
Here's an example :
select distinct(monthcolumn) from yourtable
It returns 1 instance of all the different values in the column