Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $link = mysqli_connect("sql1.njit.edu", "db526", "BRyeLmUaC", "db526");
- if(!$link){
- //echo "Error: Unable to connect to MySQL." . PHP_EOL;
- exit;
- }
- $json = file_get_contents('php://input');
- $data = json_decode($json);
- $num = $data->num;
- $q1id = $data->q1id;
- $q2id = $data->q2id;
- $q3id = $data->q3id;
- $q4id = $data->q4id;
- $q5id = $data->q5id;
- $question = [];
- for($i = 0; $i < $num; $i++){
- if($i == 0){
- $statement = "SELECT testCases from testQuestions WHERE questionID = '$q1id'";
- $result = $link->query($statement);
- if($result->num_rows > 0){
- while($row = $result->fetch_assoc()){
- $question["$q1"] = $row["testCases"];
- }
- }
- }
- if($i == 1){
- $statement = "SELECT testCases from testQuestions WHERE questionID = '$q2id'";
- $result = $link->query($statement);
- if($result->num_rows > 0){
- while($row = $result->fetch_assoc()){
- $question["$q2"] = $row["testCases"];
- }
- }
- }
- if($i == 2){
- $statement = "SELECT testCases from testQuestions WHERE questionID = '$q3id'";
- $result = $link->query($statement);
- if($result->num_rows > 0){
- while($row = $result->fetch_assoc()){
- $question["$q3"] = $row["testCases"];
- }
- }
- }
- if($i == 3){
- $statement = "SELECT testCases from testQuestions WHERE questionID = '$q4id'";
- $result = $link->query($statement);
- if($result->num_rows > 0){
- while($row = $result->fetch_assoc()){
- $question["$q4"] = $row["testCases"];
- }
- }
- }
- if($i == 4){
- $statement = "SELECT testCases from testQuestions WHERE questionID = '$q5id'";
- $result = $link->query($statement);
- if($result->num_rows > 0){
- while($row = $result->fetch_assoc()){
- $question["$q5"] = $row["testCases"];
- }
- }
- }
- }
- mysqli_close($link);
- echo json_encode($question);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement