Passing three values with a single radio button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ephialtes
    New Member
    • Jul 2007
    • 3

    Passing three values with a single radio button

    Apologies for what will doubtless be a dim question.

    I'm using Dreamweaver to put together an online profiling app. The questions (really, a series of statements) come from a table called "profiling_ques tions" and I want to store the answers in a table called "profile_answer s".

    The user is presented with a statement, and then has to click 'agree', 'strongly disagree', etc. - 6 possible outcomes.

    I want the new entry in 'profile_answer s' to include the answer (which is easy enough) but also the values of two fields in 'profiling_ques tions' that are related to the answer, but which vary depending on which question has been asked.

    So if the user is asked question ID 25, and selects 'strongly agree', there are two fields in 'profiling_ques tions' for question ID 25 called 'value_control_ strag' and 'value_market_s trag' that I want to store alongside the answer in 'profile_answer s'. And similarly if the user selects 'slightly disagree' or whatever.

    Dreamweaver 9's Developer Toolkit has built me a record insertion form that has several rows like this:

    [code=php]$ins_profile_an swers->addColumn("ans wer", "STRING_TYP E", "POST", "answer");[/code]

    the two key ones are:
    [code=php]$ins_profile_an swers->addColumn("val ue_control", "DOUBLE_TYP E", "POST", "value_control" , "{questions.val ue_control_stra g}");
    $ins_profile_an swers->addColumn("val ue_market", "DOUBLE_TYP E", "POST", "value_mark et", "{questions.val ue_market_strag ");[/code]

    I want the {questions.valu e_control_strag } at the end to vary depending on 'answer'.

    I've tried putting if ... elseif clauses around the relevant $ins_profile_an swers lines and I've also tried

    [code=php]$ins_profile_an swers->addColumn("val ue_control", "DOUBLE_TYP E", "POST", "value_control" , "{questions.val ue_control_".an swer."}");[/code]

    The first option entered every value as 0, the second every value as 1 (they should be either 10, 7, 3, -3, -7 or -10).

    Any help very gratefully appreciated.
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    Firstly, I highly recommend that you don't rely on Dreamweaver to code for you, as you'll run into dilemmas like this more than once.

    My first question would be why you want to save those values and, if you've valid reason for doing so, why you're confused as to how to do it. When making relationships between tables, you need to save the values somewhere for later usage, so you'll need to somehow attach those values to the questions. You could do so through the 'name' attribute, and then use regex to retrieve it, or set up the names using arrays whose indexes correspond to the ids.

    Comment

    • dafodil
      Contributor
      • Jul 2007
      • 389

      #3
      Originally posted by ephialtes
      Apologies for what will doubtless be a dim question.

      I'm using Dreamweaver to put together an online profiling app. The questions (really, a series of statements) come from a table called "profiling_ques tions" and I want to store the answers in a table called "profile_answer s".

      The user is presented with a statement, and then has to click 'agree', 'strongly disagree', etc. - 6 possible outcomes.

      I want the new entry in 'profile_answer s' to include the answer (which is easy enough) but also the values of two fields in 'profiling_ques tions' that are related to the answer, but which vary depending on which question has been asked.

      So if the user is asked question ID 25, and selects 'strongly agree', there are two fields in 'profiling_ques tions' for question ID 25 called 'value_control_ strag' and 'value_market_s trag' that I want to store alongside the answer in 'profile_answer s'. And similarly if the user selects 'slightly disagree' or whatever.

      Dreamweaver 9's Developer Toolkit has built me a record insertion form that has several rows like this:

      [code=php]$ins_profile_an swers->addColumn("ans wer", "STRING_TYP E", "POST", "answer");[/code]

      the two key ones are:
      [code=php]$ins_profile_an swers->addColumn("val ue_control", "DOUBLE_TYP E", "POST", "value_control" , "{questions.val ue_control_stra g}");
      $ins_profile_an swers->addColumn("val ue_market", "DOUBLE_TYP E", "POST", "value_mark et", "{questions.val ue_market_strag ");[/code]

      I want the {questions.valu e_control_strag } at the end to vary depending on 'answer'.

      I've tried putting if ... elseif clauses around the relevant $ins_profile_an swers lines and I've also tried

      [code=php]$ins_profile_an swers->addColumn("val ue_control", "DOUBLE_TYP E", "POST", "value_control" , "{questions.val ue_control_".an swer."}");[/code]

      The first option entered every value as 0, the second every value as 1 (they should be either 10, 7, 3, -3, -7 or -10).

      Any help very gratefully appreciated.
      Yeah, that's right... Don't rely on dreamweaver....

      Dreamweaver should not replace your own logic of the code.....

      And I can't understand how you want to pass those values using a radio button....

      Can you show us the code of your html design...

      Comment

      • ephialtes
        New Member
        • Jul 2007
        • 3

        #4
        Originally posted by volectricity
        Firstly, I highly recommend that you don't rely on Dreamweaver to code for you, as you'll run into dilemmas like this more than once.

        My first question would be why you want to save those values and, if you've valid reason for doing so, why you're confused as to how to do it. When making relationships between tables, you need to save the values somewhere for later usage, so you'll need to somehow attach those values to the questions. You could do so through the 'name' attribute, and then use regex to retrieve it, or set up the names using arrays whose indexes correspond to the ids.
        Thanks for the comment. Agreed I'd not ideally use Dreamweaver, but I am a newbie after all :-)

        The issue is this. A user's profile is a position on two axes, let's call them A and B. The page draws a random statement from table QUESTION, and asks them to rate how strongly they agree/disagree. Their answer gives them a certain number of 'points' on each axis, with the number of points varying depending on (i) the question and (ii) whether they are agreeing or disagreeing. What those points values should be is in table QUESTION along with each statement.

        I'm trying to store in a new row in ANSWERS, the user_id (done), the question_id (done), the answer (done) and the two numbers of points they have obtained for their answer (the problem).

        I know I could also store just user_id, question_id and answer and then look up the points values in QUESTION when I come to calculate a user's total score, but that produces quite a complicated SQL query.

        Comment

        • dafodil
          Contributor
          • Jul 2007
          • 389

          #5
          Originally posted by ephialtes
          Thanks for the comment. Agreed I'd not ideally use Dreamweaver, but I am a newbie after all :-)

          The issue is this. A user's profile is a position on two axes, let's call them A and B. The page draws a random statement from table QUESTION, and asks them to rate how strongly they agree/disagree. Their answer gives them a certain number of 'points' on each axis, with the number of points varying depending on (i) the question and (ii) whether they are agreeing or disagreeing. What those points values should be is in table QUESTION along with each statement.

          I'm trying to store in a new row in ANSWERS, the user_id (done), the question_id (done), the answer (done) and the two numbers of points they have obtained for their answer (the problem).

          I know I could also store just user_id, question_id and answer and then look up the points values in QUESTION when I come to calculate a user's total score, but that produces quite a complicated SQL query.
          To pass the user_id you need session so that you can detect who are the users who answered a questions and that means there should be a signup or login page.....

          You could pass the question_id by naming every radio button according to their group and finally you could pass the value....

          For example:

          [code=html]
          <input type="radio" name="group1" value="Milk"> Milk<br>
          <input type="radio" name="group1" value="Butter" checked> Butter<br>
          <input type="radio" name="group1" value="Cheese"> Cheese

          [/code]

          By the way there is an article posted here about sessions please check the articles on php

          Comment

          • ephialtes
            New Member
            • Jul 2007
            • 3

            #6
            Originally posted by dafodil
            To pass the user_id you need session so that you can detect who are the users who answered a questions and that means there should be a signup or login page.....

            You could pass the question_id by naming every radio button according to their group and finally you could pass the value....

            For example:

            [code=html]
            <input type="radio" name="group1" value="Milk"> Milk<br>
            <input type="radio" name="group1" value="Butter" checked> Butter<br>
            <input type="radio" name="group1" value="Cheese"> Cheese

            [/code]

            By the way there is an article posted here about sessions please check the articles on php
            Thanks, dafodil. The user id is working already (using sessions) and the question_id is also being passed in the current version. I'm really only having trouble with the two additional values that need to be looked up in QUESTIONS and passed to ANSWERS along with the user and question ids.

            Comment

            Working...