Jump to content

php-mysql dynamically storing with different values


gwolff2005

Recommended Posts

Hi guys I need your help!

 

I have a site where the user registers and then logs on. The mysql database has the following fields:

id, username, password, email, firstname, name, resultspassion, resultsmotivation, resultspassionorientation

when the user logs on he is offered to do a psychological test with 92 questions. Every question can be answered by clicking a radiogroupbutton, which value is between 0 and 5.

Every value of the answer needs to be saved either in "resultspassion", "resultsmotivation" or "resultspassionorientation".

As an example:

 

<td width="26">1</td>
      <td width="411"><strong>Do you like talking to people?</strong><br />
        </b></td>
      <td width="230">
        <div align="left">
          <input name="resultspassion1" type="radio" value="0" />
          0  
          <input name="resultspassion1" type="radio" value="1" />
          1
          <input name="resultspassion1" type="radio" value="2" />
          2
          <input name="resultspassion1" type="radio" value="3" />
          3
          <input name="resultspassion1" type="radio" value="4" />
          4
          <input name="resultspassion1" type="radio" value="5" />
      5</div></td>
    </tr>
    <tr>
      <td>2</td>
      <td>Is it important for you what other people think about you?</b></td>
      <td><p>
        <label></label>
        <label></label>
        <input name="resultsmotivation2" type="radio" value="0" />
0
<input name="resultsmotivation2" type="radio" value="1" />
1
<input name="resultsmotivation2" type="radio" value="2" />
2
<input name="resultsmotivation2" type="radio" value="3" />
3
<input name="resultsmotivation2" type="radio" value="4" />
4
<input name="resultsmotivation2" type="radio" value="5" />
5<br />
        <br />
      </p></td>
    </tr>
    <tr>
      <td>3</td>
      <td class="style1">How high is your level of excitement right now? </td>
      <td><p>
        <label></label>
        <input name="resultspassionorientation3" type="radio" value="0" />
0
<input name="resultspassionorientation3" type="radio" value="1" />
1
<input name="resultspassionorientation3" type="radio" value="2" />
2
<input name="resultspassionorientation3" type="radio" value="3" />
3
<input name="resultspassionorientation3" type="radio" value="4" />
4
<input name="resultspassionorientation3" type="radio" value="5" />
5<br />
      </p></td>

 

The test goes over three pages. My trouble now is. At the end of the page I have a go on button

<input name="Submit" type="submit" class="style1" value="go on" />

 

What can I do that

1. the answers are stored dynamically?

2. the values of teh answers are adding each time? (e.g. when I have on one page 10 questions or passion and he has at the end a value of 92 that the script counts all his values for passion together and then puts it in the table or puts each value of each answer in the table and adds them....

 

Please help!! Thanks!

Various ways but I'd use session variables as these can be passed easily between pages without the need to code anything in PHP to pass the data.

 

Once you set a session variable

$_SESSION['name']='fred';

 

Any page can access it by this:

echo $_SESSION['name'];

 

You can also have them store arrays:

$_SESSION['results']=array(1,2,3,4,5);

 

And access them:

echo $_SESSION['results'][4];

Hi Yesideez,

 

thanks for your answer. However I need to store them. because everytime the user logs in again he needs to find his results in a graph which will be printed after he finishes the test. Therefore his details need to be stored.

Depending on the result data of a question (they typing an answer? multiple choice? etc.) depends on what datatypes you need to set the fields.

 

A user typing an answer would require either VARCHAR or TEXT and multiple choice would be best suited as numerical datatypes.

 

How you INSERT/UPDATE the database depends on how you're gathering and handling the result data.

 

If you store the data in session variables as you traverse the pages then you can do one INSERT query at the end but if you're INSERTing after the first page then UPDATING as you go along you'd have to get the ID value of the first insert (presuming you've got a unique identifier set up) then use that to UPDATE with a WHERE condition.

Thanks Yesideez for taling your time. IN the first post I submitted the code I have so far. It shows that they have multiple choice options (radio buttons). But the question I have is because every value needs to bed added on top of the previous one.. How can I store them in sql like that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.