Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset="UTF-8">
- </head>
- <body>
- <?php
- require('db.php');
- function getStation($station_id, $db)
- {
- $sth = $db->prepare("SELECT name FROM station WHERE id=:station");
- $sth->execute(array(':station' => $station_id));
- $result = $sth->fetch();
- return $result;
- }
- $stationA = $_POST['A'][0];
- $stationB = $_POST['B'][0];
- //echo $stationA;
- //echo $stationB;
- $sth = $db->prepare("SELECT route_id FROM route_station WHERE station_id=:station");
- $sth->execute(array(':station' => $stationA));
- $result = $sth->fetchAll(); //from
- $count = 0;
- foreach($result as $r)
- {
- $sth2 = $db->prepare("SELECT nomer, type, station_id, seq, circled FROM route_station INNER JOIN route ON route_station.route_id=route.id WHERE route_id=:route");
- $sth2->execute(array(':route' => $r["route_id"]));
- $result2 = $sth2->fetchAll();
- foreach($result2 as $r2)
- {
- if ($r2["station_id"] == $stationB)
- {
- $seqqA = $db->prepare("SELECT seq FROM route_station WHERE (station_id=:stationA AND route_id=:route)");
- $seqqA->execute(array(':stationA' => $stationA, ':route' => $r["route_id"]));
- $tempseqA = $seqqA->fetch();
- $seqA = intval($tempseqA["seq"]);
- $seqB = intval($r2["seq"]);
- //echo $seqA;
- //echo $seqB;
- $order = $seqA > $seqB ? "DESC" : "ASC";
- if($r2["circled"])
- {
- if($seqA > $seqB)
- {
- $sth3 = $db->prepare("SELECT max(seq) FROM route_station WHERE route_id=:route");
- $sth3->execute(array(':route' => $r["route_id"]));
- $result3 = $sth3->fetch();
- $max = $result3["max(seq)"];
- $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
- seq BETWEEN :seq1 AND :maxseq AND route_id=:route ORDER BY seq ASC");
- $sth3->execute(array(':seq1' => $seqA, ':maxseq' => $max, ':route' => $r["route_id"]));
- $result3 = $sth3->fetchAll();
- echo '�а�����: '.$r2["nomer"]." (к�л��евий)</br>";
- echo '<img src="vtc/img/'.$r2["type"].'.png">';
- foreach($result3 as $fff)
- echo $fff["name"].'->';
- $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
- seq BETWEEN 1 AND :seqB AND route_id=:route ORDER BY seq ASC");
- $sth3->execute(array(':seqB' => $seqB, ':route' => $r["route_id"]));
- $result3 = $sth3->fetchAll();
- foreach($result3 as $fff)
- echo $fff === end($result3)?$fff["name"]:$fff["name"].'->';
- echo "<br>";
- }
- else if($seqA < $seqB)
- {
- $sth3 = $db->prepare("SELECT max(seq) FROM route_station WHERE route_id=:route");
- $sth3->execute(array(':route' => $r["route_id"]));
- $result3 = $sth3->fetch();
- $max = $result3["max(seq)"];
- $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
- seq BETWEEN 1 AND :seqA AND route_id=:route ORDER BY seq DESC");
- $sth3->execute(array(':seqA' => $seqA, ':route' => $r["route_id"]));
- $result3 = $sth3->fetchAll();
- echo '�а�����: '.$r2["nomer"]." (к�л��евий)</br>";
- echo '<img src="vtc/img/'.$r2["type"].'.png">';
- foreach($result3 as $fff)
- echo $fff["name"].'->';
- $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
- seq BETWEEN :seqB AND :max AND route_id=:route ORDER BY seq DESC");
- $sth3->execute(array(':max' => $max, ':seqB' => $seqB, ':route' => $r["route_id"]));
- $result3 = $sth3->fetchAll();
- foreach($result3 as $fff)
- echo $fff === end($result3)?$fff["name"]:$fff["name"].'->';
- echo "<br>";
- }
- }
- $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
- seq BETWEEN :seq1 AND :seq2 AND route_id=:route ORDER BY seq $order");
- $sth3->execute(array(':seq1' => $seqA < $seqB ? $seqA : $seqB, ':seq2' => $seqA > $seqB ? $seqA : $seqB,
- ':route' => $r["route_id"]));
- $result3 = $sth3->fetchAll();
- if($r2["circled"])
- $circled = " (к�л��евий)";
- else $circled = '';
- echo '�����'.': '.$r2["nomer"].$circled."</br>";
- echo '<img src="vtc/img/'.$r2["type"].'.png">';
- foreach($result3 as $fff)
- echo $fff === end($result3)?$fff["name"]:$fff["name"].'->';
- echo "<br>";
- $count++;
- }
- }
- }
- if ($count == 0)
- {
- echo '���ого не знайдено';
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement