我正在使用jquery mobile构建火车时刻表站点。在每个站点页面上,它提供了离开该站点的服务,每个服务都是可折叠的标题,当点击它时,它会显示该运行的站点的完整列表,以及列车到达每个站点的时间。它对于第一个工作正常,但对于所有其他工作,在正确的列表开始之前有2个随机实例,第一个是大写字母,下一个是数字。使用屏幕截图可能更容易解释 - First one(工作正常),Second one(随机位,此后的所有其他位置相同,但字母和数字看似随机变化)。它为什么这样做,它们来自哪里,更重要的是我如何摆脱它们?
编辑:这封信似乎是点击之前服务的第一个字母(所以如果第一个字母以B开头,那么随机字母将是第二个字母的B)。
编辑:这个号码是火车在服务之前终止的时间的起始号码(因此,如果它在70分钟后终止,则数字为7,如果是4小时,则为4(我有它)因此,当小时数为2或更多时,它会缩短到几个小时))
代码:
// ^ start of html document, connect to db etc.
<?php
try {
$sql = "SELECT timetable.id as id, day, station, departs as time, CURTIME(), ROUND(TIME_TO_SEC(departs)/60 - TIME_TO_SEC(CURTIME())/60,0) as departs, platform, route, run, route.code, line.name, station.name as terminus, line.colour FROM timetable INNER JOIN route ON timetable.route = route.id INNER JOIN line ON route.line = line.id INNER JOIN station ON route.terminus = station.id WHERE station = " . $_GET['id'] . " AND day LIKE '%" . date('N') . "%' AND departs > CURTIME() ORDER BY time ASC";
$s = $pdo->prepare($sql);
$s->execute();
}
catch (PDOException $e){
}
foreach($s as $row){
$services[] = array('id' => $row['id'], 'time' => $row['time'], 'platform' => $row['platform'], 'terminus' => $row['terminus'], 'colour' => $row['colour'], 'departs' => $row['departs'], 'route' => $row['route'], 'run' => $row['run']);
}
?>
<body>
<!-- Home -->
<div data-role="page" id="homepage">
<div data-theme="a" data-role="header" align="center">
<a data-role="button" data-transition="none" href="search.php"
class="ui-btn-left" data-icon="arrow-l" data-ajax="false">
Back
</a>
<h3>
<?php echo $name;?> Station
</h3>
</div>
<div data-role="content">
<div style=" text-align:center" data-controltype="image" id="stationpic">
<img style="width: 300px; height: px" src="images/<?php echo $name;?> Station.jpg">
</div>
<ul data-role="listview" data-divider-theme="b" data-inset="true">
<li data-theme="a" data-icon="false">
<?php if(isset($services)){?>
<div data-role="collapsible-set">
<table style="width:100%; color:#ffffff !important; text-align:left !important;">
<tr><td style="width:15%; padding-left:5%;">Service</td><td style="width:55%;">Destination</td><td style="width:15%;">Platform</td><td style="width:15%;">Departs</td></tr>
</table>
<?php for($i = 0; $i < count($services); $i++){?>
<div data-role="collapsible" data-collapsed="true" data-theme="none" style="background-color:<?php echo $services[$i]['colour'];?>; background-image:none !important;">
<h3>
<table style="width:100%; color:#ffffff !important; text-align:left !important;">
<tr><td style="width:15%;"><?php echo $services[$i]['time'];?></td><td style="width:55%;"><?php if($services[$i]['terminus'] == $name){ echo 'Terminating Service'; } else { echo $services[$i]['terminus']; }?></td><td style="width:15%;"><?php echo $services[$i]['platform'];?></td><td style="width:15%;"><?php if($services[$i]['departs'] >= 120){ echo floor($services[$i]['departs']/60) . ' hrs'; } else { echo $services[$i]['departs'] . ' min'; }?></td></tr>
</table>
</h3>
<?php
try {
$stations = "SELECT station.name as station, ROUND(TIME_TO_SEC(departs)/60 - TIME_TO_SEC(CURTIME())/60,0) as departs FROM timetable INNER JOIN station ON timetable.station = station.id WHERE route = " . $services[$i]['route'] . " AND run = " . $services[$i]['run'] . " AND departs > '" . $services[$i]['time'] . "' ORDER BY departs ASC";
$z = $pdo->prepare($stations);
$z->execute();
}
catch (PDOException $error){
}
foreach($z as $z){
$stops[] = array('station' => $z['station'], 'departs' => $z['departs']);
}
if(isset($stops)){
foreach($stops as $stops){
if($stops['departs'] >= 120){
$stops['departs'] = floor($stops['departs']/60) . ' hrs';
} else {
$stops['departs'] = $stops['departs'] . ' min';
}
echo '<div style="margin-left:15%;">' . $stops['station'] . ' - ' . $stops['departs'] . '</div>';
}
}?>
<!--Further Trip Details Coming Soon-->
</div>
<?php } ?>
</div>
<?php } else {?>
No Services For The Rest Of Today
<?php } ?>
</li>
</ul>
</div>
<div data-role="footer" data-theme="a">
<h3>Copyright</h3>
</div>
</div>
</body>
答案 0 :(得分:0)
我已经完成了一项解决外部问题的工作,但潜在的问题仍然存在。
随机部分使终止服务行为不正确,在出现之后只出现一个其他非终止服务而不管限制并返回各种错误。将if($services[$i]['terminus'] != $name){
置于代码之前以获取并回显服务上的停靠点可解决该问题。随机部分保留在非终止服务上。无论如何,第一个是一封信,下一个是一个数字。因为它们是为了显示站点和出发时间以分钟或小时为单位,所以通过在回显站点之前检查if(strlen($stops['departs']) > 1 && strlen($stops['departs']) > 1){
来删除这些“结果”。所以它“解决了”,但问题仍然存在,我只是隐藏了它。所以我不会接受这个答案,以防有人能真正解决它