0 and $row_looping['repeat'] != "" and $row_looping['repeat'] > 0 and ($_SESSION['num_skip_forms'] == 0)) { $_SESSION['looping'] = true; //boolean for whether we are currently in a loop or not $_SESSION['loop_end'] = $row_looping['form_order']; //set current location as loop end $_SESSION['loop_iter'] = 1; //keeps track of the number of loop iterations progressed $_SESSION['loop_repeat'] = $row_looping['repeat']; //keep track of total # of repeats $_SESSION['loop_goto'] = $row_looping['goto']; //loop_goto keeps track of beginning of loop //if looping back to the same form handler, just increment the trial number //if looping back to a different form handler, set 'last_visited' and reset trial number if($_SESSION['loop_goto'] != $_SESSION['last_visited']) { $_SESSION['last_visited'] = $row_looping['goto']; } } //if after checking for a loop, there is none, then just go to the next form else { //if skipping forms, increment by that number instead and then zero out //the num_skip_forms variable. if($_SESSION['num_skip_forms'] != 0) { $_SESSION['last_visited'] += $_SESSION['num_skip_forms']; $_SESSION['num_skip_forms'] = 0; } else $_SESSION['last_visited']++; } } //otherwise, if we are currently in a loop, do the following else { $skipping_forms = (isset($_SESSION['num_skip_forms']) && ($_SESSION['num_skip_forms'] != 0)); if($skipping_forms) { $_SESSION['last_visited'] += $_SESSION['num_skip_forms']; $_SESSION['num_skip_forms'] = 0; if($_SESSION['last_visited'] > $_SESSION['loop_end']) clear_loop_vars(); } //if we have reached the end of the loop, do some checking elseif($_SESSION['last_visited'] >= $_SESSION['loop_end']) { //we have reached the end of the loop again, so increase the loop iteration counter $_SESSION['loop_iter']++; //if at the end of the loop we have reached the last iteration, clear all loop info out and go to next form if($_SESSION['loop_iter'] == $_SESSION['loop_repeat']) { clear_loop_vars(); $_SESSION['last_visited']++; } else { //otherwise, if we haven't reached the last iteration, go back to the beginning of the loop //if looping back to the same form, just increment the trial number //if looping back to a different form, set 'last_visited' and reset trial number if($_SESSION['loop_goto'] != $_SESSION['last_visited']) { $_SESSION['last_visited'] = $_SESSION['loop_goto']; } } } else { //if we are not at the end of the loop just go to the next form $_SESSION['last_visited']++; } } } $query_next_form = sprintf("SELECT * from experiment_x_form LEFT JOIN form on (form.form_id = experiment_x_form.form_id) WHERE experiment_id = %s AND form_order = %d", $_SESSION['experiment_id'],$_SESSION['last_visited']); mysql_select_db($database_subject,$subject); $next_form = mysql_query($query_next_form, $subject) or report_error_form(mysql_error()); $row_next_form = mysql_fetch_assoc($next_form); $next_filename = $questionnaire_location."form_processing/".$row_next_form['form_handler']; header("Location: $next_filename"); exit; ?>