Commit d313153d authored by Adarsh's avatar Adarsh

get questions debug

parent 423753be
<?php <?php
header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true'); header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE"); header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header("Content-Type: application/json; charset=UTF-8"); header("Content-Type: application/json; charset=UTF-8");
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
$mysqli = new mysqli($db_host, $db_username, $db_password,$db_name); $mysqli = new mysqli($db_host, $db_username, $db_password,$db_name);
if ($mysqli->connect_error) { if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
} }
?> ?>
\ No newline at end of file
...@@ -8,13 +8,14 @@ header("Content-Type: application/json; charset=UTF-8"); ...@@ -8,13 +8,14 @@ header("Content-Type: application/json; charset=UTF-8");
include_once("../database.php"); include_once("../database.php");
if($_SERVER['REQUEST_METHOD'] === '$_GET'){
$sql1 = "SELECT Now()"; $sql1 = "SELECT Now()";
$currtime = $mysqli->query($sql1); $currtime = $mysqli->query($sql1);
// $sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime"; // $sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime";
$sql2 = "SELECT * FROM questions"; $sql2 = "SELECT * FROM questions";
$data = []; $data = [];
if($result = mysqli->query($sql2)){ if($result = $mysqli->query($sql2)){
$i = 0; $i = 0;
while($row = mysql_fetch_assoc($result)){ while($row = mysql_fetch_assoc($result)){
...@@ -35,28 +36,17 @@ include_once("../database.php"); ...@@ -35,28 +36,17 @@ include_once("../database.php");
else{ else{
http_response_code(404); http_response_code(404);
} }
}
// if($_SERVER['REQUEST_METHOD'] === 'GET'){ // if($_SERVER['REQUEST_METHOD'] === '$_GET'){
// $sql1 = "SELECT Now()"; // $sql1 = "SELECT Now()";
// $currtime = $mysqli->query($sql1); // $currtime = $mysqli->query($sql1);
// $sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime"; // $sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime";
// $data = []; // $data = [];
// if($result = mysqli->query($sql2)){ // if($result = $mysqli->query($sql2)){
// while($row = mysql_fetch_assoc($request)){
// $i = 0; // array_push($data,$row);
// while($row = mysql_fetch_assoc($result)){
// $data[$i]['title'] = $row['title'];
// $data[$i]['username'] = $row['username'];
// $data[$i]['statement'] = $row['statement'];
// $data[$i]['tc1'] = $row['tc1'];
// $data[$i]['out1'] = $row['out1'];
// $data[$i]['tc2'] = $row['tc2'];
// $data[$i]['out2'] = $row['out2'];
// $data[$i]['stime'] = $row['stime'];
// $data[$i]['etime'] = $row['etime'];
// $i++;
// } // }
// echo json_encode($data); // echo json_encode($data);
// } // }
......
...@@ -26,7 +26,9 @@ export class HomeComponent implements OnInit { ...@@ -26,7 +26,9 @@ export class HomeComponent implements OnInit {
stime: "", stime: "",
etime: "" etime: ""
}; };
questions: any[];
questions: Question[];
errorMessage: any;
constructor(private dataService: ApiService, constructor(private dataService: ApiService,
private problemService: ProblemService, private problemService: ProblemService,
...@@ -39,8 +41,12 @@ export class HomeComponent implements OnInit { ...@@ -39,8 +41,12 @@ export class HomeComponent implements OnInit {
this.getProblems(); this.getProblems();
this.questionService.getQues() this.questionService.getQues()
.subscribe(questions => this.questions = questions); .subscribe(data => {
// console.log(this.questions); this.questions = data;
},
error => this.errorMessage = <any>error);
console.log(this.questions);
} }
getProblems(): void { getProblems(): void {
......
...@@ -20,8 +20,8 @@ export class QuestionService { ...@@ -20,8 +20,8 @@ export class QuestionService {
return this.http.post(this.uploadUrl, ques); return this.http.post(this.uploadUrl, ques);
} }
getQues(): Observable<any[]> { getQues(): Observable<Question[]> {
return this.http.get<any[]>(this.getUrl); return this.http.get<Question[]>(this.getUrl);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment