Commit 08f56200 authored by Adarsh's avatar Adarsh

get ques complete

parent 0563df13
...@@ -8,51 +8,30 @@ header("Content-Type: application/json; charset=UTF-8"); ...@@ -8,51 +8,30 @@ header("Content-Type: application/json; charset=UTF-8");
include_once("../database.php"); include_once("../database.php");
if($_SERVER['REQUEST_METHOD'] === '$_GET'){ $sql2 = "SELECT * FROM questions";
$sql1 = "SELECT Now()";
$currtime = $mysqli->query($sql1); $data = array();
// $sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime";
$sql2 = "SELECT * FROM questions"; if($result = $mysqli->query($sql2)){
$data = []; $i = 0;
if($result = $mysqli->query($sql2)){ while($row = mysqli_fetch_assoc($result)){
$i = 0; $data[$i]['title'] = $row['title'];
while($row = mysql_fetch_assoc($result)){ $data[$i]['username'] = $row['username'];
$data[$i]['statement'] = $row['statement'];
$data[$i]['title'] = $row['title']; $data[$i]['tc1'] = $row['tc1'];
$data[$i]['username'] = $row['username']; $data[$i]['out1'] = $row['out1'];
$data[$i]['statement'] = $row['statement']; $data[$i]['tc2'] = $row['tc2'];
$data[$i]['tc1'] = $row['tc1']; $data[$i]['out2'] = $row['out2'];
$data[$i]['out1'] = $row['out1']; $data[$i]['stime'] = $row['stime'];
$data[$i]['tc2'] = $row['tc2']; $data[$i]['etime'] = $row['etime'];
$data[$i]['out2'] = $row['out2']; $i++;
$data[$i]['stime'] = $row['stime'];
$data[$i]['etime'] = $row['etime'];
$i++;
}
echo json_encode($data);
}
else{
http_response_code(404);
} }
echo json_encode($data);
}
else{
http_response_code(404);
} }
// if($_SERVER['REQUEST_METHOD'] === '$_GET'){
// $sql1 = "SELECT Now()";
// $currtime = $mysqli->query($sql1);
// $sql2 = "SELECT * FROM questions WHERE stime <= $currtime and etime >= $currtime";
// $data = [];
// if($result = $mysqli->query($sql2)){
// while($row = mysql_fetch_assoc($request)){
// array_push($data,$row);
// }
// echo json_encode($data);
// }
// else{
// http_response_code(404);
// }
// }
?> ?>
...@@ -28,6 +28,7 @@ export class HomeComponent implements OnInit { ...@@ -28,6 +28,7 @@ export class HomeComponent implements OnInit {
}; };
questions: Question[]; questions: Question[];
ques_final: Question[] = [];
errorMessage: any; errorMessage: any;
constructor(private dataService: ApiService, constructor(private dataService: ApiService,
...@@ -43,10 +44,24 @@ export class HomeComponent implements OnInit { ...@@ -43,10 +44,24 @@ export class HomeComponent implements OnInit {
this.questionService.getQues() this.questionService.getQues()
.subscribe(data => { .subscribe(data => {
this.questions = data; this.questions = data;
// console.log(this.questions);
this.organizeQues();
}, },
error => this.errorMessage = <any>error); error => this.errorMessage = <any>error
);
}
organizeQues(): void {
this.questions.forEach(element => {
let d = new Date();
let s = new Date(element.stime);
let e = new Date(element.etime);
if(s < d && e > d) {
this.ques_final.push(element);
}
});
console.log(this.questions); // console.log(this.ques_final);
} }
getProblems(): void { getProblems(): void {
......
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