Help Looping Through Survey Questions

Discussion in 'ASP General' started by Colin Steadman, Sep 20, 2004.

  1. I've create a simple survey using ASP. Its finished and
    works, but one aspect of my coding is annoying me and I
    cant figure out a better way of doing it.

    Basically the questions are stored in an Access 2000 table
    like this:

    QUESTION_NUMBER QUESTION
    1 Question 1 text....
    2 Question 2 text....
    3 Question 3 text....
    4 Question 4 text....
    5 Question 5 text....

    My ASP page gets these questions and displays them in a
    form dynamically. The user then answers the questions by
    clicking radio buttons (Agree, Tend to agree, Not sure...
    ect).

    This works well and if I want to add a question I just
    update the database table.

    The problem is I've not been able to figure out how to
    make the submit page dynamic. I'm having to manually add
    code to my submit page to look after each question
    individually rather than looping through the Form
    collection.

    For example when I build the SQL to update the database I
    have to do it like this (note the last five lines look
    after the responses to my five questions):

    ReDim sqlValues(40)

    sqlValues(0) = "values ("
    sqlValues(1) = "'" & Session("emp_no") & "', "
    sqlValues(2) = "'" & Session("Username") & "', "
    sqlValues(3) = "'" & Session("sex") & "', "
    sqlValues(4) = "'" & Session("phone") & "', "
    sqlValues(5) = "'" & Session("job_title") & "', "
    sqlValues(6) = "'" & Session("department") & "', "
    sqlValues(7) = "'" & Session("age") & "', "
    sqlValues(8) = "'" & Session("grade") & "', "
    sqlValues(9) = "'" & Request.Form("1") & "', "
    sqlValues(10) = "'" & Request.Form("2") & "', "
    sqlValues(11) = "'" & Request.Form("3") & "', "
    sqlValues(12) = "'" & Request.Form("4") & "', "
    sqlValues(13) = "'" & Request.Form("5") & "', "
    ...

    sql = Join(sqlValues)

    Is there any possible way I can avoid having to hard code
    the above and have the page work out what it needs to do
    dynamically?

    TIA,

    Colin
     
    Colin Steadman, Sep 20, 2004
    #1
    1. Advertising

  2. "Colin Steadman" <> wrote in message
    news:216501c49f17$619a68b0$...
    > I've create a simple survey using ASP. Its finished and
    > works, but one aspect of my coding is annoying me and I
    > cant figure out a better way of doing it.
    >
    > Basically the questions are stored in an Access 2000 table
    > like this:
    >
    > QUESTION_NUMBER QUESTION
    > 1 Question 1 text....
    > 2 Question 2 text....
    > 3 Question 3 text....
    > 4 Question 4 text....
    > 5 Question 5 text....
    >
    > My ASP page gets these questions and displays them in a
    > form dynamically. The user then answers the questions by
    > clicking radio buttons (Agree, Tend to agree, Not sure...
    > ect).
    >
    > This works well and if I want to add a question I just
    > update the database table.
    >
    > The problem is I've not been able to figure out how to
    > make the submit page dynamic. I'm having to manually add
    > code to my submit page to look after each question
    > individually rather than looping through the Form
    > collection.
    >
    > For example when I build the SQL to update the database I
    > have to do it like this (note the last five lines look
    > after the responses to my five questions):
    >
    > ReDim sqlValues(40)
    >
    > sqlValues(0) = "values ("
    > sqlValues(1) = "'" & Session("emp_no") & "', "
    > sqlValues(2) = "'" & Session("Username") & "', "
    > sqlValues(3) = "'" & Session("sex") & "', "
    > sqlValues(4) = "'" & Session("phone") & "', "
    > sqlValues(5) = "'" & Session("job_title") & "', "
    > sqlValues(6) = "'" & Session("department") & "', "
    > sqlValues(7) = "'" & Session("age") & "', "
    > sqlValues(8) = "'" & Session("grade") & "', "
    > sqlValues(9) = "'" & Request.Form("1") & "', "
    > sqlValues(10) = "'" & Request.Form("2") & "', "
    > sqlValues(11) = "'" & Request.Form("3") & "', "
    > sqlValues(12) = "'" & Request.Form("4") & "', "
    > sqlValues(13) = "'" & Request.Form("5") & "', "
    > ...
    >
    > sql = Join(sqlValues)
    >
    > Is there any possible way I can avoid having to hard code
    > the above and have the page work out what it needs to do
    > dynamically?


    try this:
    http://www.aspfaq.com/show.asp?id=2036

    --
    Tom Kaminski IIS MVP
    http://www.microsoft.com/windowsserver2003/community/centers/iis/
    http://mvp.support.microsoft.com/
    http://www.iisfaq.com/
    http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
    http://www.tryiis.com
     
    Tom Kaminski [MVP], Sep 20, 2004
    #2
    1. Advertising

  3. Colin Steadman

    Jeff Cochran Guest

    On Mon, 20 Sep 2004 06:40:24 -0700, "Colin Steadman"
    <> wrote:

    >I've create a simple survey using ASP. Its finished and
    >works, but one aspect of my coding is annoying me and I
    >cant figure out a better way of doing it.


    There's a lot of sample ASP code out there to do surveys, take a look
    at some of the methodology. Survey responses are not the easiest
    things to code when you allow multiple types of questions, you may
    find a canned package is cheap compared to your time.

    Jeff

    >
    >Basically the questions are stored in an Access 2000 table
    >like this:
    >
    >QUESTION_NUMBER QUESTION
    >1 Question 1 text....
    >2 Question 2 text....
    >3 Question 3 text....
    >4 Question 4 text....
    >5 Question 5 text....
    >
    >My ASP page gets these questions and displays them in a
    >form dynamically. The user then answers the questions by
    >clicking radio buttons (Agree, Tend to agree, Not sure...
    >ect).
    >
    >This works well and if I want to add a question I just
    >update the database table.
    >
    >The problem is I've not been able to figure out how to
    >make the submit page dynamic. I'm having to manually add
    >code to my submit page to look after each question
    >individually rather than looping through the Form
    >collection.
    >
    >For example when I build the SQL to update the database I
    >have to do it like this (note the last five lines look
    >after the responses to my five questions):
    >
    > ReDim sqlValues(40)
    >
    > sqlValues(0) = "values ("
    > sqlValues(1) = "'" & Session("emp_no") & "', "
    > sqlValues(2) = "'" & Session("Username") & "', "
    > sqlValues(3) = "'" & Session("sex") & "', "
    > sqlValues(4) = "'" & Session("phone") & "', "
    > sqlValues(5) = "'" & Session("job_title") & "', "
    > sqlValues(6) = "'" & Session("department") & "', "
    > sqlValues(7) = "'" & Session("age") & "', "
    > sqlValues(8) = "'" & Session("grade") & "', "
    > sqlValues(9) = "'" & Request.Form("1") & "', "
    > sqlValues(10) = "'" & Request.Form("2") & "', "
    > sqlValues(11) = "'" & Request.Form("3") & "', "
    > sqlValues(12) = "'" & Request.Form("4") & "', "
    > sqlValues(13) = "'" & Request.Form("5") & "', "
    > ...
    >
    > sql = Join(sqlValues)
    >
    >Is there any possible way I can avoid having to hard code
    >the above and have the page work out what it needs to do
    >dynamically?
    >
    >TIA,
    >
    >Colin
     
    Jeff Cochran, Sep 20, 2004
    #3
  4. "Tom Kaminski [MVP]" <tomk (A@T) mvps (D.O.T) org> wrote in message news:<cimou7$>...

    >
    > try this:
    > http://www.aspfaq.com/show.asp?id=2036




    Hummm... thanks Tom, I think I can use the ideas in that example.

    Cheers,

    Colin
     
    Colin Steadman, Sep 21, 2004
    #4
  5. (Jeff Cochran) wrote in message news:<>...
    >
    > There's a lot of sample ASP code out there to do surveys, take a look
    > at some of the methodology.


    I did try looking for some examples, but this project came from
    no-where without warning and I was only given a day to sort it out. I
    literally had to scrawl some ideas on a bit of paper and got cracking.
    It was great fun though.


    > Survey responses are not the easiest
    > things to code when you allow multiple types of questions, you may
    > find a canned package is cheap compared to your time.
    >
    > Jeff
    >


    I was fortunate that all the questions were to be answered in the same
    way. If it has been a jumble of question types I wouldn't have had a
    chance.

    Colin
     
    Colin Steadman, Sep 21, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aemca
    Replies:
    1
    Views:
    571
    Aemca
    Jul 22, 2003
  2. Diva
    Replies:
    1
    Views:
    542
    S. Justin Gengo
    Jul 24, 2003
  3. Replies:
    1
    Views:
    82
  4. Aaron
    Replies:
    2
    Views:
    530
    dhtml
    Apr 10, 2011
  5. Replies:
    5
    Views:
    279
Loading...

Share This Page