Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. <?php
  2.  
  3. $link = mysqli_connect("sql1.njit.edu", "db526", "BRyeLmUaC", "db526");
  4.  
  5. if(!$link){
  6. //echo "Error: Unable to connect to MySQL." . PHP_EOL;
  7. exit;
  8. }
  9.  
  10. $json = file_get_contents('php://input');
  11. $data = json_decode($json);
  12. $num = $data->num;
  13. $q1id = $data->q1id;
  14. $q2id = $data->q2id;
  15. $q3id = $data->q3id;
  16. $q4id = $data->q4id;
  17. $q5id = $data->q5id;
  18. $question = [];
  19.  
  20. for($i = 0; $i < $num; $i++){
  21. if($i == 0){
  22. $statement = "SELECT testCases from testQuestions WHERE questionID = '$q1id'";
  23.  
  24. $result = $link->query($statement);
  25.  
  26.  
  27. if($result->num_rows > 0){
  28. while($row = $result->fetch_assoc()){
  29. $question["$q1"] = $row["testCases"];
  30. }
  31. }
  32. }
  33. if($i == 1){
  34. $statement = "SELECT testCases from testQuestions WHERE questionID = '$q2id'";
  35.  
  36. $result = $link->query($statement);
  37.  
  38.  
  39. if($result->num_rows > 0){
  40. while($row = $result->fetch_assoc()){
  41. $question["$q2"] = $row["testCases"];
  42. }
  43. }
  44. }
  45. if($i == 2){
  46. $statement = "SELECT testCases from testQuestions WHERE questionID = '$q3id'";
  47.  
  48. $result = $link->query($statement);
  49.  
  50.  
  51. if($result->num_rows > 0){
  52. while($row = $result->fetch_assoc()){
  53. $question["$q3"] = $row["testCases"];
  54. }
  55. }
  56. }
  57. if($i == 3){
  58. $statement = "SELECT testCases from testQuestions WHERE questionID = '$q4id'";
  59.  
  60. $result = $link->query($statement);
  61.  
  62.  
  63. if($result->num_rows > 0){
  64. while($row = $result->fetch_assoc()){
  65. $question["$q4"] = $row["testCases"];
  66. }
  67. }
  68. }
  69. if($i == 4){
  70. $statement = "SELECT testCases from testQuestions WHERE questionID = '$q5id'";
  71.  
  72. $result = $link->query($statement);
  73.  
  74.  
  75. if($result->num_rows > 0){
  76. while($row = $result->fetch_assoc()){
  77. $question["$q5"] = $row["testCases"];
  78. }
  79. }
  80. }
  81.  
  82. }
  83. mysqli_close($link);
  84.  
  85. echo json_encode($question);
  86.  
  87.  
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement