Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta charset="UTF-8">
  4. </head>
  5. <body>
  6. <?php
  7. require('db.php');
  8. function getStation($station_id, $db)
  9. {
  10. $sth = $db->prepare("SELECT name FROM station WHERE id=:station");
  11. $sth->execute(array(':station' => $station_id));
  12. $result = $sth->fetch();
  13. return $result;
  14. }
  15. $stationA = $_POST['A'][0];
  16. $stationB = $_POST['B'][0];
  17. //echo $stationA;
  18. //echo $stationB;
  19.  
  20. $sth = $db->prepare("SELECT route_id FROM route_station WHERE station_id=:station");
  21. $sth->execute(array(':station' => $stationA));
  22. $result = $sth->fetchAll(); //from
  23. $count = 0;
  24. foreach($result as $r)
  25. {
  26. $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");
  27. $sth2->execute(array(':route' => $r["route_id"]));
  28. $result2 = $sth2->fetchAll();
  29. foreach($result2 as $r2)
  30. {
  31. if ($r2["station_id"] == $stationB)
  32. {
  33. $seqqA = $db->prepare("SELECT seq FROM route_station WHERE (station_id=:stationA AND route_id=:route)");
  34. $seqqA->execute(array(':stationA' => $stationA, ':route' => $r["route_id"]));
  35. $tempseqA = $seqqA->fetch();
  36. $seqA = intval($tempseqA["seq"]);
  37. $seqB = intval($r2["seq"]);
  38. //echo $seqA;
  39. //echo $seqB;
  40. $order = $seqA > $seqB ? "DESC" : "ASC";
  41. if($r2["circled"])
  42. {
  43. if($seqA > $seqB)
  44. {
  45. $sth3 = $db->prepare("SELECT max(seq) FROM route_station WHERE route_id=:route");
  46. $sth3->execute(array(':route' => $r["route_id"]));
  47. $result3 = $sth3->fetch();
  48. $max = $result3["max(seq)"];
  49. $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
  50. seq BETWEEN :seq1 AND :maxseq AND route_id=:route ORDER BY seq ASC");
  51. $sth3->execute(array(':seq1' => $seqA, ':maxseq' => $max, ':route' => $r["route_id"]));
  52. $result3 = $sth3->fetchAll();
  53. echo '�а�����: '.$r2["nomer"]." (к�л��евий)</br>";
  54. echo '<img src="vtc/img/'.$r2["type"].'.png">';
  55. foreach($result3 as $fff)
  56. echo $fff["name"].'->';
  57. $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
  58. seq BETWEEN 1 AND :seqB AND route_id=:route ORDER BY seq ASC");
  59. $sth3->execute(array(':seqB' => $seqB, ':route' => $r["route_id"]));
  60. $result3 = $sth3->fetchAll();
  61. foreach($result3 as $fff)
  62. echo $fff === end($result3)?$fff["name"]:$fff["name"].'->';
  63. echo "<br>";
  64. }
  65. else if($seqA < $seqB)
  66. {
  67. $sth3 = $db->prepare("SELECT max(seq) FROM route_station WHERE route_id=:route");
  68. $sth3->execute(array(':route' => $r["route_id"]));
  69. $result3 = $sth3->fetch();
  70. $max = $result3["max(seq)"];
  71. $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
  72. seq BETWEEN 1 AND :seqA AND route_id=:route ORDER BY seq DESC");
  73. $sth3->execute(array(':seqA' => $seqA, ':route' => $r["route_id"]));
  74. $result3 = $sth3->fetchAll();
  75. echo '�а�����: '.$r2["nomer"]." (к�л��евий)</br>";
  76. echo '<img src="vtc/img/'.$r2["type"].'.png">';
  77. foreach($result3 as $fff)
  78. echo $fff["name"].'->';
  79. $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
  80. seq BETWEEN :seqB AND :max AND route_id=:route ORDER BY seq DESC");
  81. $sth3->execute(array(':max' => $max, ':seqB' => $seqB, ':route' => $r["route_id"]));
  82. $result3 = $sth3->fetchAll();
  83. foreach($result3 as $fff)
  84. echo $fff === end($result3)?$fff["name"]:$fff["name"].'->';
  85. echo "<br>";
  86. }
  87. }
  88.  
  89.  
  90. $sth3 = $db->prepare("SELECT station.name FROM route_station INNER JOIN station ON route_station.station_id=station.id WHERE
  91. seq BETWEEN :seq1 AND :seq2 AND route_id=:route ORDER BY seq $order");
  92. $sth3->execute(array(':seq1' => $seqA < $seqB ? $seqA : $seqB, ':seq2' => $seqA > $seqB ? $seqA : $seqB,
  93. ':route' => $r["route_id"]));
  94. $result3 = $sth3->fetchAll();
  95. if($r2["circled"])
  96. $circled = " (к�л��евий)";
  97. else $circled = '';
  98. echo '�����'.': '.$r2["nomer"].$circled."</br>";
  99. echo '<img src="vtc/img/'.$r2["type"].'.png">';
  100. foreach($result3 as $fff)
  101. echo $fff === end($result3)?$fff["name"]:$fff["name"].'->';
  102. echo "<br>";
  103. $count++;
  104. }
  105. }
  106. }
  107. if ($count == 0)
  108. {
  109. echo '���ого не знайдено';
  110. }
  111.  
  112. ?>
  113. </body>
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement