Click to See Complete Forum and Search --> : [RESOLVED] Counting Records from an INNER JOIN within a loop


cinematic_jesi
09-09-2008, 11:51 AM
Okay, this is basically what I've got going on. I have a page where users can submit videos and vote written in ASP/VBScript. Then in 2 SQL tables I have TblPepTalkSubmissions and TblPepTalkVotes.

I'm creating an admin panel where I can manage the submissions, I'd like to have a current vote count to go along on the same page. This is where I'm having trouble.

I did a SQL Statement like this in my database:

SELECT TblPepTalkSubmissions.ID, COUNT(1) AS Expr1
FROM TblPepTalkSubmissions INNER JOIN
TblPepTalkVotes ON TblPepTalkVotes.VideoID = TblPepTalkSubmissions.ID
GROUP BY TblPepTalkSubmissions.ID

And for example it would return the following:
ID | Expr1
2 | 31
3 | 2
24 | 9

Okay this is where I get lost, because I'm new to ASP. I created a recordset in Dreamweaver CS3 with the exact statement to avoid errors:
<%
Dim Submissions
Dim Submissions_cmd
Dim Submissions_numRows

Set Submissions_cmd = Server.CreateObject ("ADODB.Command")
Submissions_cmd.ActiveConnection = MM_local_STRING
Submissions_cmd.CommandText = "SELECT TblPepTalkSubmissions.ID, COUNT(1) AS Expr1 FROM TblPepTalkSubmissions INNER JOIN TblPepTalkVotes ON TblPepTalkVotes.VideoID = TblPepTalkSubmissions.ID GROUP BY TblPepTalkSubmissions.ID "
Submissions_cmd.Prepared = true

Set Submissions = Submissions_cmd.Execute
Submissions_numRows = 0
%>
Then I have a loop. Which loops all the records for the Submissions table. I have a column in the table labeled "Votes" and so I tried placing the Expr1 Column into the Table Column so that it would show the vote count for each submission. Welllllll........ as you probably already know, that didn't work. It just repeats "31" for all of them (see example above).

Anyone have any suggestions?

cinematic_jesi
09-09-2008, 03:16 PM
Nevermind, I just created one recordset with everything that I needed to display. Just having a moment :)