Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Multiple Database Record Quantities on ASP Page
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

JohnC
Junior Member

215 Posts

Posted - 25 December 2007 :  12:49:24  Show Profile
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  Show Profile  Send ruirib a Yahoo! Message

<%
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
Go to Top of Page

JohnC
Junior Member

215 Posts

Posted - 25 December 2007 :  16:23:03  Show Profile
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
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 25 December 2007 :  18:51:54  Show Profile  Send ruirib a Yahoo! Message
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
Go to Top of Page

JohnC
Junior Member

215 Posts

Posted - 26 December 2007 :  11:46:20  Show Profile
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...
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 26 December 2007 :  22:20:43  Show Profile  Send ruirib a Yahoo! Message
What would you want the header to look like. Do you want to use tables to layout the thing?


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

JohnC
Junior Member

215 Posts

Posted - 27 December 2007 :  10:02:01  Show Profile
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
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 27 December 2007 :  10:05:23  Show Profile  Send ruirib a Yahoo! Message
Sorry, lost you there. What is that for?


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

JohnC
Junior Member

215 Posts

Posted - 27 December 2007 :  10:13:56  Show Profile
This can't be this hard. There's so many Web sites out there with quantities listed for categories and things...
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 27 December 2007 :  10:21:45  Show Profile  Send ruirib a Yahoo! Message
It's not hard at all, I just don't know what you want to show and how you want the layout to be.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 27 December 2007 :  18:40:07  Show Profile  Send pdrg a Yahoo! Message
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.
Go to Top of Page

JohnC
Junior Member

215 Posts

Posted - 28 December 2007 :  10:00:14  Show Profile
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!
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 28 December 2007 :  11:50:58  Show Profile  Send ruirib a Yahoo! Message
You have yet to tell me what you want displayed on the header.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

pdrg
Support Moderator

United Kingdom
2897 Posts

Posted - 29 December 2007 :  14:05:10  Show Profile  Send pdrg a Yahoo! Message
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 ;-)
Go to Top of Page

JohnC
Junior Member

215 Posts

Posted - 11 January 2008 :  20:04:14  Show Profile
That's the problem, I don't know what needs to go in the header. That's why I'm asking.
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 11 January 2008 :  20:38:43  Show Profile  Send ruirib a Yahoo! Message
What do you want to go there? That's what matters, no?


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.51 seconds. Powered By: Snitz Forums 2000 Version 3.4.07