我有一個數據庫表,用於存儲城市的航班信息,包括Destination_ID,Destinatination_City,Airline,Leaving_From和Arriving。SQL打印出兩行?
我運行以下查詢:
$name = $_GET['name'];
$dbQuery = $db->prepare("SELECT * FROM DESTINATIONS
WHERE destination_City = '$name' ");
$dbQuery->execute();
$airlines= array();
while ($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)){
$Airlines[] = $dbRow['Airline']; }
foreach($Airlines as $Airline)
{
$dbQuery = $db->prepare("SELECT * FROM DESTINATIONS
WHERE Airline = '$Airline' AND Destination_City = '$name' ");
$dbQuery->execute();
while ($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)){
$Arriving = $dbRow ['Arriving'];
$Leaving_From = $dbRow ['Leaving_From'] ; }
echo "$Leaving_From to $Arriving" ;
}
此返回兩個結果與除了到達的列是不同的值相同。但是,在打印時,打印第二行兩次而不是打印兩行。
我不知道它爲什麼這樣做。誰能幫忙?
你需要在'while'中放置'echo'。正如當前寫入的,變量被最後一次檢索到的行覆蓋 – kero 2015-02-11 12:42:42
@kingkero剛剛嘗試過這種方式,現在它打印第1行兩次,第2行打印兩次? – OUDK 2015-02-11 12:47:32
你有任何其他的代碼包含/調用張貼的行嗎? – kero 2015-02-11 12:48:52