Author |
Topic |
JohnC
Junior Member
215 Posts |
Posted - 25 December 2007 : 12:49:24
|
I want to add multiple instances on an ASP page of database table records (count records). For example: I have ‘x’ amount of video categories and ‘x’ amount of videos in each category. I want to add the quantity of videos in each category, like “Video One (24), Video Two (12), etc.” The code I came up with, which I know works, is as follows:<%
Dim xConn
xConn = MM_connVid_STRING
Dim xSQL
xSQL = "Select Count(Category) AS xTotal FROM Vids WHERE Category='x'"
Dim xRS
Set xRS = Server.CreateObject("ADODB.RecordSet")
xRS.Open xSQL, xConn
Response.Write xRS("xTotal")
xRS.Close
Set xRS = Nothing
xConn.Close
Set xConn = Nothing
%> However, instead of writing the above code for each category, which could be a hundred times on the page, I’m sure there’s a way to write the code once and then ‘call out’ with just a snippet. Appreciate any help on this topic! |
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 25 December 2007 : 15:58:17
|
<%
Dim xConn
xConn = MM_connVid_STRING
Dim xSQL
xSQL = "SELECT Category, Count(*) As xTotal FROM Vids GROUP By Category
Dim xRS
Set xRS = Server.CreateObject("ADODB.RecordSet")
xRS.Open xSQL, xConn
While Not xRS.EOF
Response.Write xRS("Category") & " Total: " & xRS("xTotal")
xRs.MoveNext
Wend
xRS.Close
Set xRS = Nothing
xConn.Close
Set xConn = Nothing
%>
|
Snitz 3.4 Readme | Like the support? Support Snitz too |
|
|
JohnC
Junior Member
215 Posts |
Posted - 25 December 2007 : 16:23:03
|
Thanks, Rui! That's not much different than what I had. I guess I'm looking to see how I could do it with less code for each category. Like defining terms in the header and then just using a snippet for each category, like: <%=(rsVid.Fields.Item("Count").Value)%> |
Edited by - JohnC on 25 December 2007 16:24:10 |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 25 December 2007 : 18:51:54
|
quote: Originally posted by JohnC
Thanks, Rui! That's not much different than what I had. I guess I'm looking to see how I could do it with less code for each category. Like defining terms in the header and then just using a snippet for each category, like: <%=(rsVid.Fields.Item("Count").Value)%>
In the previous code, there is just one statement per category, but you could just write a header before, no issues with that. You can just remove the "Total :" part. |
Snitz 3.4 Readme | Like the support? Support Snitz too |
|
|
JohnC
Junior Member
215 Posts |
Posted - 26 December 2007 : 11:46:20
|
Again I'm still in learning stages, Rui. Can you please give me a sample of what to put in the header and what to put at each place on the page where I want totals to appear?
In addition to the header, I'd like to be able to write just snippets for each category. For example:
1. Rock Videos (<%=(rsVidRock.Fields.Item("Count").Value)%>) - Produces: "1. Rock Videos (24)"
2. Pop Videos (<%=(rsVidPop.Fields.Item("Count").Value)%>) - Produces: "2. Pop Videos (16)"
3. etc... |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
|
JohnC
Junior Member
215 Posts |
Posted - 27 December 2007 : 10:02:01
|
I'm assuming the header will need to define the parameters, something like:
<%
Set MM_rs = rsVids
MM_rsCount = rsVids_total
MM_uniqueCol = "VidID"
MM_paramName = "VidID"
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%> It looks like it may be similar to Snitz "members.asp" page, where it shows members and the number of posts for each... but in my case it would be a list of categories and the number of videos in each category. Maybe I'll start looking at that code... |
Edited by - JohnC on 27 December 2007 10:11:43 |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
|
JohnC
Junior Member
215 Posts |
Posted - 27 December 2007 : 10:13:56
|
This can't be this hard. There's so many Web sites out there with quantities listed for categories and things... |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
|
pdrg
Support Moderator
United Kingdom
2897 Posts |
Posted - 27 December 2007 : 18:40:07
|
flag- MM_ variables are dreamweaver created code, which can be dreadful to try to work with as dw code can be awfully clunky one size fits all kind of stuff - at least that was the case 8-9 years back! It could be easier to code from scratch or accept being limited by what the dw macros can create - you'll lose all code maintainability if you just cobble so neither dw nor man can understand it, and possibly open yourself to SQL injection attacks. |
|
|
JohnC
Junior Member
215 Posts |
Posted - 28 December 2007 : 10:00:14
|
Right, I'm working with existing sample code trying to modify it to do what I need. I'm open to using entirely new code if you know something what will work for my intended application. Like I said, I’m a total newbie! |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
|
pdrg
Support Moderator
United Kingdom
2897 Posts |
Posted - 29 December 2007 : 14:05:10
|
JohnC, Well good luck learning! Personally I'd not start by assuming Dreamweaver code was good or efficient to copy, instead I'd tell Rui what he asks, he's great - he's a total Snitz hero ;-) |
|
|
JohnC
Junior Member
215 Posts |
Posted - 11 January 2008 : 20:04:14
|
That's the problem, I don't know what needs to go in the header. That's why I'm asking. |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
|
Topic |
|