-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduleFindCode.php
71 lines (51 loc) · 2.26 KB
/
scheduleFindCode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Created by PhpStorm.
* User: Abid
* Date: 13/05/2018
* Time: 07:58 PM
*/
$stationName = ($_POST['stationName']);
$mrtNo = ($_POST['mrtNo']);
$dirrection = ($_POST['dirrection']);
$conf= include 'Api/server_conf.php';
$host = $conf['server_host'];
$user = $conf['server_username'];
$pass = $conf['server_password'];
$db = $conf['server_dbname'];
$db_connect = new mysqli($host,$user,$pass,$db) or die('unable to connect');
//echo 'Done connecting Database'."\n\n";
$qry12 = "SELECT * FROM station WHERE station.stationName = '$dirrection';";
$res12 = $db_connect->query($qry12) or die('bad query 12');
$row12 = $res12->fetch_assoc();
$dirrectionId = $row12["stationId"];
$qry1 = "SELECT mrt.mrtStartP1, stop.reachTimeFromP1, mrt.mrtStartP2, stop.reachTimeFromP2 FROM station NATURAL JOIN stop NATURAL JOIN mrt
WHERE station.stationName = '$stationName' AND stop.mrtNo = $mrtNo;";
$res1 = $db_connect->query($qry1) or die('bad query 1');
$row1 = $res1->fetch_assoc();
$mrtStartP1 = $row1["mrtStartP1"];
$mrtStartP2 = $row1["mrtStartP2"];
$reachTimeFromP1 = $row1["reachTimeFromP1"];
$reachTimeFromP2 = $row1["reachTimeFromP2"];
if($dirrectionId == $mrtStartP1){ //$mrtStartP1 er stationId
//echo "From ".$mrtStartP2. " takes ". $reachTimeFromP2 ." minutes" . " Dirrection ". $mrtStartP1. "<p>";
echo "Station Name : ". $stationName . "<p>". "Dirrection : ". $dirrection. "<p><p>";
$qry2 = "SELECT DATE_ADD(mrtschedule.startTime, INTERVAL $reachTimeFromP2 MINUTE) as time FROM mrtschedule
WHERE mrtschedule.startStation = $mrtStartP2
AND mrtschedule.mrtNo = $mrtNo;";
$res2 = $db_connect->query($qry2) or die('bad query 2');
while ($row2 = $res2->fetch_assoc()){
echo $row2["time"]."<br>";
}
}
else if($dirrectionId == $mrtStartP2){
echo "Station Name : ". $stationName . "<p>". "Dirrection : ". $dirrection. "<p><p>";
$qry3 = "SELECT DATE_ADD(mrtschedule.startTime, INTERVAL $reachTimeFromP1 MINUTE) as time FROM mrtschedule
WHERE mrtschedule.startStation = $mrtStartP1
AND mrtschedule.mrtNo = $mrtNo;";
$res3 = $db_connect->query($qry3) or die('bad query 3');
while ($row3 = $res3->fetch_assoc()){
echo $row3["time"]."<br>";
}
}
?>