我有兩個表tour_foreign
&數據庫tour_foreign_residence
,並希望合併這兩表在一起得到的PHP代碼的輸出如下例:將幾個數據庫表結合在一起?
我的表和值是:
我想得到作爲輸出tour_foreign.id = tour_foreign_residence.relation
:
One-week tour of Istanbul_1 | 88888 & 99999 $ 112233 $ 445566 | Three nights and two days | 15:29
One-week tour of Istanbul_2 | 55555 & 66666 $ 77777 | Three nights and two days | 12:03
One-week tour of Istanbul_3 | 11111 & 22222 $ 33333 $ 44444 | Three nights and two days | 12:03
我的嘗試是這樣的,但它不給我什麼,我想在上面:
$this -> db -> query("
SELECT
@rownum := @rownum + 1 rownum,
tour_foreign.id,
tour_foreign.name,
tour_foreign_residence.name_re,
tour_foreign.term,
tour_foreign.time_go,
tour_foreign.time_back,
tour_foreign.type_of_vehicle
FROM tour_foreign
INNER JOIN tour_foreign_residence
ON (tour_foreign.id = tour_foreign_residence.relation)
JOIN (SELECT @rownum := 0) r
WHERE tour_foreign.name LIKE "%' . $find . '%"
OR tour_foreign_residence.name_re LIKE "%' . $find . '%"
")
如何解決這個問題?
請告訴我,它是如何在我的代碼? –
我無法測試你的實際查詢,但你可以從添加到你的SELECT語句開始:GROUP_CONCAT(tour_foreign_residence.name_re ORDER BY tour_foreign_residence.name_re SEPERATOR「$」) –
我在WHERE之後添加它,但是得到這個錯誤:'Error編號:1064 您的SQL語法有錯誤;請查看與您的MySQL服務器版本相對應的手冊,以便在第18行'GROUP_CONCAT(tour_foreign_residence.name_re ORDER BY tour_foreign_residence.nam')使用的正確語法使用' –