mChaloBEST/svr/busStatus.php
2011-08-13 18:12:40 +05:30

40 lines
1.2 KiB
PHP

<?php include("../local/config.php");
include("../local/dbconn2.php");
if($conn) {
$stopnameid = $_GET['s'];
// $stopnameid = $_POST['s'];
$tblHtml = '<table class="tbl_color" id="busStatus">';
$tblHtml = $tblHtml . '<tr><th>Bus no.</th><th>Direction</th><th>Distance from you</th><th>ETA</th></tr>';
$bUp = true;
$bDn = true;
$sqlstatus = 'CALL GetNearBus("' . $stopnameid . '")';
// echo $sqlstatus;
foreach ($conn2->query($sqlstatus) as $rowstat) {
$bno = $rowstat['busno'];
$di = $rowstat['distance'];
$tm = round($di / 1000 * 2); // Assuming speed of 30 km/hr
$dir = $rowstat['direction'];
if($dir == 'u' && $bUp) {
$tblHtml = $tblHtml . '<tr><td>' . $bno . '</td><td>U</td><td>'
. $di . ' m</td><td>' . $tm . ' min</td></tr>';
// echo '<br>u ' . $tblHtml;
$bUp = false;
}
else if($dir == 'd' && $bDn) {
$tblHtml = $tblHtml . '<tr><td>' . $bno . '</td><td>D</td><td>'
. $di . ' m</td><td>' . $tm . ' min</td></tr>';
// echo '<br>d ' . $tblHtml;
$bDn = false;
}
if(!$bUp && !$bDn)
break;
}
}
$tblHtml = $tblHtml . '</table>';
echo $tblHtml;
/*** close the database connection ***/
$conn = null;
?>