暂无描述

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. require_once 'config.php';
  3. require_once 'dbh.inc.php'; // has to use proyecto.ema.upr DB!!!
  4. require_once 'checkLogin.php';
  5. // include("../conection.php");
  6. if(isset($_POST['export']) && isset($_POST['id_exp'])) {
  7. $id_experience = mysqli_real_escape_string($connection, $_POST['id_exp']);
  8. // $id_student = mysqli_real_escape_string($connection, $_POST['id_student']);
  9. // $res_type = mysqli_real_escape_string($connection, $_POST['res_type']);
  10. header_remove();
  11. header('Content-Type: text/csv; charset=utf-8');
  12. header('Content-Disposition: attachment; filename="Resultados_'.$id_experience.'.csv"');
  13. $output = fopen('php://output', 'w');
  14. // $answersQuery = "SELECT a.id_student, a.id_subquestionnair, a.id_question, a.value FROM `answer` a, `question` q WHERE `id_subquestionnair` IN (SELECT `id_subquestionnair` FROM experience_subquestionnair WHERE `id_experience`=10);";
  15. // $resultAnswers = mysqli_query($connection, $answersQuery);
  16. // while($rowAnswers = mysqli_fetch_assoc()) {
  17. // $rowAnswers['value'];
  18. // }
  19. // $subquestionnairQuery = "SELECT `title` FROM `subquestionnair` WHERE `id`=".id_subquestionnair.";
  20. // id_subquestionnair: se usará para el nombre del subquestionnair
  21. // id_question: premise, id_category, id_subcategory
  22. /*** QUEREMOS: question premise, question category, question subcategory, student id, subquestionnair title, answer value ***/
  23. // (CORRADA) GENERA 1541 FILAS PERO ES CON NÚMEROS NADA MÁS
  24. $query = "SELECT DISTINCT q.id, q.premise, q.id_category, q.id_subcategory, a.id_student, a.id_subquestionnair, a.value FROM `experience_questionnair` eq, `subquestionnair` qs, `questionnair_question` qq, `question` q, `answer` a WHERE a.id_question=q.id and eq.id_questionnair=qs.id_questionnair and eq.id_questionnair=qq.id_questionnair and qq.id_question=q.id and eq.id_experience=".$id_experience." ORDER BY q.id, a.id_subquestionnair, a.id_student ASC;";
  25. $header = array('Question ID', 'Question Premise', 'Corresponding Moment', 'Question Category', 'Question Subcategory', 'Student ID', 'Answer');
  26. // (VÍCTOR) GENERA 1215 FILAS
  27. // $query = "SELECT q.premise, a.value, sq.title, c.categoria, sc.subcategoria, a.id_student FROM answer a, question q, subquestionnair sq, category c, subcategory sc WHERE (a.`id_subquestionnair` IN (SELECT `id_subquestionnair` FROM experience_subquestionnair WHERE `id_experience`=".$id_experience.")) AND q.id=a.id_question AND sq.id=a.id_subquestionnair AND c.id=q.id_category AND sc.id=q.id_subcategory;";
  28. // $header = array('Question Premise', 'Answer', 'Corresponding Moment', 'Question Category', 'Question Subcategory', 'Student ID');
  29. fputcsv($output, $header);
  30. $result = mysqli_query($connection, $query);
  31. while($row = mysqli_fetch_assoc($result)) {
  32. $queryCategory = "SELECT categoria FROM `category` WHERE id=".$row['id_category'].";";
  33. $resultCategory = mysqli_query($connection, $queryCategory);
  34. $rowCategory = mysqli_fetch_assoc($resultCategory);
  35. // QUERY USES SUBCATEGORY ID FROM ANOTHER SELECT BECAUSE $row['id_subcategory'] GIVES AN ERROR
  36. $querySubcategory = "SELECT subcategoria FROM `subcategory` WHERE id=(SELECT id_subcategory FROM `question` WHERE id=".$row['id'].");";
  37. $resultSubcategory = mysqli_query($connection, $querySubcategory);
  38. $rowSubcategory = mysqli_fetch_assoc($resultSubcategory);
  39. $queryMoment = "SELECT title FROM `subquestionnair` WHERE id=".$row['id_subquestionnair'].";";
  40. $resultMoment = mysqli_query($connection, $queryMoment);
  41. $rowMoment = mysqli_fetch_assoc($resultMoment);
  42. fputcsv($output, array($row['id'], $row['premise'], $rowMoment['title'], $rowCategory['categoria'], $rowSubcategory['subcategoria'], $row['id_student'], $row['value']));
  43. }
  44. fclose($output);
  45. }
  46. ?>