gwolff2005 Posted April 20, 2009 Share Posted April 20, 2009 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! Link to comment https://forums.phpfreaks.com/topic/154840-php-mysql-dynamically-storing-with-different-values/ Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 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]; Link to comment https://forums.phpfreaks.com/topic/154840-php-mysql-dynamically-storing-with-different-values/#findComment-814340 Share on other sites More sharing options...
gwolff2005 Posted April 20, 2009 Author Share Posted April 20, 2009 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. Link to comment https://forums.phpfreaks.com/topic/154840-php-mysql-dynamically-storing-with-different-values/#findComment-814343 Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 Then save them inside a database. You can either use flatfile (write data to the server) or use a MySQL database to store the data for retrieval at a later date, MySQL would be best here. Link to comment https://forums.phpfreaks.com/topic/154840-php-mysql-dynamically-storing-with-different-values/#findComment-814349 Share on other sites More sharing options...
gwolff2005 Posted April 20, 2009 Author Share Posted April 20, 2009 Hi yesideez, thanks! when I opened the topic I wrote that I have already the mysql database and the table set up. The question is I have no clue how to get the different values ADDED in the different rows of the table. Link to comment https://forums.phpfreaks.com/topic/154840-php-mysql-dynamically-storing-with-different-values/#findComment-814351 Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 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. Link to comment https://forums.phpfreaks.com/topic/154840-php-mysql-dynamically-storing-with-different-values/#findComment-814356 Share on other sites More sharing options...
gwolff2005 Posted April 20, 2009 Author Share Posted April 20, 2009 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? Link to comment https://forums.phpfreaks.com/topic/154840-php-mysql-dynamically-storing-with-different-values/#findComment-814360 Share on other sites More sharing options...
Yesideez Posted April 20, 2009 Share Posted April 20, 2009 UPDATE can add numbers together quite easily. mysql_query("UPDATE table SET `myfield`=`myfield`+1 WHERE `questionid`=".$qid); Link to comment https://forums.phpfreaks.com/topic/154840-php-mysql-dynamically-storing-with-different-values/#findComment-814367 Share on other sites More sharing options...
gwolff2005 Posted April 20, 2009 Author Share Posted April 20, 2009 Hi Yesideez and everyone else, I still don't get it. How can I define every single radiobutton being saved to another row? Link to comment https://forums.phpfreaks.com/topic/154840-php-mysql-dynamically-storing-with-different-values/#findComment-814876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.