我正在尝试编写一个查询,从我的数据库中获取火车列表,用户将输入真实姓名,第一个查询将获取车站或“tiploc”的代码,然后在第二个查询中使用它。出于某种原因,我没有得到任何回报,我确信这与从获取中获取的数据有关,因为如果我对 Tiploc 进行硬编码,它可以正常工作。我在 php 方面相当薄弱,所以任何帮助都会很棒!谢谢
<?
mysql_connect("localhost","root","XXXXXX")
or die ("No connection could be made to the OpenRail
Database");mysql_select_db("autotrain");
$query1 = "SELECT tiploc_code FROM allstations WHERE c LIKE 'Cradley Heath';";
$result1 =mysql_query($query1);
$tiploc=null;
while($row = mysql_fetch_assoc($result1)){
$tipoc=$row['tiploc_code'];
}
$query2 = "SELECT allstations.C, locations.public_departure
FROM `locations` , allstations, schedules_cache,schedules
WHERE locations.id = schedules_cache.id
AND schedules_cache.id = schedules.id
AND '2012-11-11' BETWEEN schedules.date_from AND schedules.date_to
AND locations.tiploc_code = '$tiploc'
AND locations.public_departure >=1600
AND locations.public_departure <=1700
AND schedules.runs_su LIKE '1'
AND schedules_cache.destination = allstations.tiploc_code
ORDER BY locations.public_departure ASC;";
$result2=mysql_query($query2);
while($row = mysql_fetch_assoc($result2)){
echo($row['C']);
}
?>