Major Stations

Shanghai Beijing Nanjing Hangzhou Tianjin Suzhou

Major Train Lines

Shanghai to Nanjing via Suzhou, Wuxi, Changzhou, Zhenjiang

Shanghai to Hangzhou via Jiaxing

'; $template =& new Template("train.tmpl"); $template->AddParam('htmlintro', $htmlintro); $template->AddParam('Title', $title); $template->EchoOutput(); exit; } $sqlwhere = ' 1 = 1 '; if($trainno != '') { if(substr($trainno, -1, 1) == '%') $sqlwhere .= " AND trainno LIKE '$trainno'"; else $sqlwhere .=" AND trainno = '$trainno' "; $title = "Train # $trainno"; } if($stationname != '') { $sqlwhere .=" AND stationname = '$stationname' "; $title = "$stationname Station"; } mysql_connect('localhost', 'wangjian_public', 'Password01!'); mysql_select_db('wangjian_public'); if($from != '' && $to !='') { $title = "Train from $from to $to"; if($via != '') $title .= " via " . implode(', ', array_reverse($vias)); $htmlintro = "

Train from $to to $from

"; if($via != '') { $rvias = array_reverse($vias); $htmlintro = "

Train from $to to $from via " . implode(', ', $rvias) . "

"; } $htmlintro = "
$htmlintro
Train from to
"; $htmltable .= " " . "
Train #$from ->"; if($via != '') foreach($vias as $v) $htmltable .= "$v ->"; $htmltable .= "$toDurationDistance (km)"; $sql = "SELECT * FROM train_trains WHERE stationname LIKE '$from' ORDER BY dept, trainno, seq LIMIT 500"; $results = mysql_query($sql) or die ("Sorry: " . mysql_error() . "
$sql"); while($line = mysql_fetch_array($results)) { $ismatch = false; $res = mysql_query("SELECT * FROM train_trains WHERE trainno = '{$line['trainno']}'"); $linestations = array(); while($ln = mysql_fetch_array($res)) { $linestations[$ln['stationname']] = $ln['dept']; if(strtolower($ln['stationname']) == strtolower($to) && $line['seq'] < $ln['seq']) { $tag_isstart = $line['seq'] == 1 ? ">" : "  "; $tag_isend = (mysql_num_rows($res) == count($linestations)) ? "<":"  "; $ismatch = true; $htmlvia = ''; if($via != '') foreach($vias as $v) $htmlvia .= "
" . $linestations[$v]; $htmltable .= "
{$line['trainno']}$tag_isstart{$line['dept']}". $htmlvia . "{$ln['arrv']}$tag_isend". "" . travel_time($line['dept'], $ln['arrv']) . "" . ($ln['dist'] - $line['dist']); } } } $htmltable .= "
"; $template =& new Template("train.tmpl"); //$template->AddParam('Trains', $trains); //$template->AddParam('Stationname', $stationname); $template->AddParam('htmlintro', $htmlintro); $template->AddParam('Title', $title); $template->AddParam('htmlfooter', $htmlfooter); $template->AddParam("htmltable", $htmltable); $template->EchoOutput(); exit; } $sql = "SELECT * FROM train_trains WHERE $sqlwhere ORDER BY trainno, seq LIMIT 500"; $results = mysql_query($sql) or die ("Sorry: " . mysql_error() . "
$sql"); $trains = array(); if($stationname != '') $htmlintro = "

From $stationname to
From to $stationname
"; while($line = mysql_fetch_array($results)) { $trains[] = array( 'id' => $line['id'], 'trainno' => $line['trainno'], 'seq' => $line['seq'], 'page' => $line['page'], 'stationno' => $line['stationno'], 'stationname' => $line['stationname'], 'arrv' => format_time($line['arrv']), 'dept' => format_time($line['dept']), 'dist' => $line['dist'], ); } $majorstations = array ('Shanghai', 'Beijing', 'Nanjing', 'Hangzhou', 'Guangzhou'); foreach($majorstations as $m) $htmlmajorstations .= "$m
"; $template =& new Template("train.tmpl"); $template->AddParam('Trains', $trains); $template->AddParam('htmlintro', $htmlintro); $template->AddParam('Stationname', $stationname); $template->AddParam('Title', $title); $template->AddParam('htmlfooter', $htmlfooter); $template->AddParam("tableheader", "
Train #SeqStation NameArriveDepartDistance"); $template->EchoOutput(); ?>