yoda69 Posted April 13, 2010 Share Posted April 13, 2010 Hey, I'm designing an online psychological experiment that use several php pages. In every page there is another question or questionnaire. ALL the data generated in these pages go to the same mysql table. My design right now update the same row for different fields (for the same user) in every single page of the experiment. I was thinking that it probably consumes a lot of time and traffic to access the database in every page and update the same row for the different fields. Can anyone suggest a better way of doing so? Is there a method to store all the data in a temp location and then update it once to the database? Thanks Link to comment https://forums.phpfreaks.com/topic/198357-designing-multiple-php-pages/ Share on other sites More sharing options...
conker87 Posted April 13, 2010 Share Posted April 13, 2010 How are you distinguishing between users? If you're using unique IDs then all you need to do it: $query = "UPDATE `*questions_table*` SET `*question1*` = '*answer1* WHERE `user` = $id"; Obviously change the asterisked values to your table name, question field and answer variable respectively. edit If I'd read your questions correctly, then I'd get the gist of what you wanted. It's not that much traffic really. But if you did want to do it, use sessions. //top of page session_start(); // Place each answer to the question into a session: $_SESSION['question1'] = $answer1; // Do this on all 3 pages, then after question 3, take the form to a page that updates all 3 fields in your database with the session values. Link to comment https://forums.phpfreaks.com/topic/198357-designing-multiple-php-pages/#findComment-1040810 Share on other sites More sharing options...
yoda69 Posted April 13, 2010 Author Share Posted April 13, 2010 Thanks for the answer. I think I will rather use sessions. However, what I still don't get is how to pass the variable data from the form into a variable in the same page. for example here is my code: <?php session_start();?> <html> <head> </head> <body> <div id="container"> <form id="form1" method="post" action=""> <label>Fill this Data <input type="text" name="1" id="1" /> </label> <p> <label> <input type="submit" name="2" id="2" value="Submit" /> </label> </p> </form> <?php $_SESSION['question1'] = $answer1; ?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/198357-designing-multiple-php-pages/#findComment-1040826 Share on other sites More sharing options...
yoda69 Posted April 13, 2010 Author Share Posted April 13, 2010 Okay got it by transfering the data with the form to the next page I can store the information into the session variable. Thanks Link to comment https://forums.phpfreaks.com/topic/198357-designing-multiple-php-pages/#findComment-1040914 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.