"; print_r($_REQUEST['position']); echo ""; exit; // First start to find the id of the survey we are moving Down. $sql = "SELECT question_id FROM section_questions WHERE sort_order='" . ($_REQUEST['position'] - 1) . "'"; $res = db_query($sql); $row = mysql_fetch_assoc($res); // This is the id of the record that is moving Down one position. $id_moving_down = $row['question_id']; // Move it up one. $sql = "UPDATE section_questions SET sort_order='" . ($_REQUEST['position'] - 1) . "' WHERE question_id='" . $_REQUEST['q_id'] . "'"; $res = db_query($sql); // Now move the one that was on top, down one. $sql = "UPDATE section_questions SET sort_order='" . $_REQUEST['position'] . "' WHERE question_id='" . $id_moving_down . "'"; $res = db_query($sql); // Refresh the page. header("Location: list.php"); exit; } // The user has chosen to move a section down one in the sort order. // Only sections < max(sort_order) are allowed to do this. This is // Checked when the page is loaded. if(isset($_REQUEST['Move_Q_Down'])) { $sql = "SELECT question_id FROM section_questions WHERE sort_order='" . ($_REQUEST['position'] + 1) . "'"; $res = db_query($sql); $row = mysql_fetch_assoc($res); // This is the id of the record that is moving Up one position. $id_moving_down = $row['question_id']; // Move it up one. $sql = "UPDATE section_questions SET sort_order='" . ($_REQUEST['position'] + 1) . "' WHERE question_id='" . $_REQUEST['q_id'] . "'"; $res = db_query($sql); // Now move the one that was on top, down one. $sql = "UPDATE section_questions SET sort_order='" . $_REQUEST['position'] . "' WHERE question_id='" . $id_moving_down . "'"; $res = db_query($sql); header("Location: list.php"); exit; } /* End Submission Checks */ /* * Begin onLoad * This section loops through all the surveys and checks to see if sections * exist for that survey. If there are sections, then loop through all of them * checking to see if questions exist for each itteration. If there are questions * print them out. * */ // --Survey // // $sql = "SELECT survey_id, survey_title, sort_order FROM surveys ORDER BY sort_order ASC"; $sur_res = db_query($sql); while($sur_row = mysql_fetch_assoc($sur_res)) { $html .= '
Survey Title:
' . $sur_row['survey_title'] . '
 
'; // // // $sql = "SELECT section_id, section_title, sort_order FROM survey_sections WHERE survey_id='" . $sur_row['survey_id'] . "' ORDER BY sort_order ASC"; $sec_res = db_query($sql); if(mysql_num_rows($sec_res) > 0) { while($sec_row = mysql_fetch_assoc($sec_res)) { $m_sql = "SELECT max(sort_order) AS sec_max, min(sort_order) AS sec_min FROM survey_sections WHERE survey_id='" . $sur_row['survey_id'] . "'"; $m_res = db_query($m_sql); $m_row = mysql_fetch_assoc($m_res); $sec_max = $m_row['sec_max']; $sec_min = $m_row['sec_min']; $html .= '
Section Title:
' . $sec_row['section_title'] . '
 
'; // // // $q_sql = "SELECT question_id, question, sort_order FROM section_questions WHERE section_id='" . $sec_row['section_id'] . "' ORDER BY sort_order ASC"; $q_res = db_query($q_sql); if(mysql_num_rows($q_res) > 0) { while($q_row = mysql_fetch_assoc($q_res)) { $m_sql = "SELECT max(sort_order) AS q_max, min(sort_order) AS q_min FROM section_questions WHERE section_id='" . $sec_row['section_id'] . "' ORDER BY sort_order ASC"; $m_res = db_query($m_sql); $m_row = mysql_fetch_assoc($m_res); $q_max = $m_row['q_max']; $q_min = $m_row['q_min']; $html .= '
Question:
' . $q_row['question'] . '
 
'; } } } } } ?>