SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Getting the count from database where all initial values are empty

    I have a registration form that I'm making and I need to get the count of available spots for each class session. I can't get the array to return something like "0,0,0,0,0,0". Is there a way to do this? There are 6 total classes and they are named 1, 2, 3, 4, 5, and 6.

    When you start out, each count will be 0 (meaning no one signed up yet) which makes the openSpots variable equal to 35 (maximum # allowed).
    **********************************************************
    <%
    Set my_rs = Server.CreateObject("ADODB.Recordset")

    my_sql = "SELECT COUNT(response) AS classCount, cast(question AS varchar) AS className FROM survey WHERE surveyName='Survey' GROUP BY cast(question as varchar)"

    my_rs.open my_sql, my_conn

    dim classCountArrayStr, classNameArrayStr
    classCountArrayStr = ""
    classNameArrayStr = ""

    if not(my_rs.bof and my_rs.eof) then
    do while not (my_rs.eof)
    classCountArrayStr = classCountArrayStr & my_rs.fields("classCount") & ","
    classNameArrayStr = classNameArrayStr & my_rs.fields("className") & ","
    my_rs.movenext
    loop
    my_rs.close
    end if

    if classNameArrayStr = "" then 'first time using this page so no values are set yet
    classNameArrayStr = "1,2,3,4,5,6"
    end if
    %>
    ...... unrelated code in between

    <%
    dim classNameArray, classCountArray, openSpots
    classNameArray = split(classNameArrayStr,",") 'class values: array(1,2,3,4,5,6)
    ' classCountArray = split(classCountArrayStr,",")
    %>

    ..... unrelated code in between
    <%
    if classCountArray(i) < 35 then
    openSlots = 35 - classCountArray(i) '35 slots allowed maximum
    end if
    %>

    When I try to use classCountArray(i) I get an error saying "Type mismatch" or "script out of range". The values are first a string and then are converted over to an array. It doesn't find anything for the counts since they are all empty. I'm sure this is something easy, but I've been working on trying to get this to work for like a day now with no luck.

    In the SQL statement, the values are being cast into varchars because the database has the fields set up as type memo since it's a re-useable table.

  2. #2
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Things that we need to know if you have tried:

    Have you ran the query in your DBMS (sql server, i'm assuming)?
    Did the results come back as expected?
    Did you write out the results on your web page?

    Code:
    do while not (my_rs.eof) 
    response.write(my_rs.fields("classCount") & "," & my_rs.fields("className")) & vbcrlf
    my_rs.movenext
    loop
    For the script out of range error, you could try declaring your array as follows:

    dim classNameArray(5)

    Since you will always have 6 elements in your array, you don't need a dynamic array and you can define the array index.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •