簡體   English   中英

不工作在sql INNER JOIN中?

[英]Not work WHERE IN sql INNER JOIN?

我希望WHERE數據選擇$ find,但它(WHERE)在以下查詢中不起作用,我的輸出There is not ,怎么修復它?

$find="hello";
$query = $this->db->query('
SELECT tour_foreign.name, 
       tour_foreign_residence.name_re, 
       tour_foreign_airline.name_airline, 
       tour_foreign.service, 
       tour_foreign.date_go, 
       tour_foreign.date_back, 
       tour_foreign.term 
FROM   tour_foreign 
       INNER JOIN tour_foreign_residence 
         ON ( tour_foreign.id = tour_foreign_residence.relation ) 
       INNER JOIN tour_foreign_airline 
         ON ( tour_foreign.id = tour_foreign_airline.relation ) 
WHERE  tour_foreign.name LIKE "%' . $find . '%" 
        OR tour_foreign_residence.name_re LIKE "%' . $find . '%"


');

if ($query->num_rows() > 0) {
    foreach ($query->result() as $val) {
        echo $val->name . '<br>';
    }
} else {
    echo 'There is not';
}

WHERE之前有一個額外的逗號(在tour_foreign_airline.relation之后)。

編輯:我看到你現在修好了,但是JOIN看起來仍然不對勁。 嘗試這個:

INNER JOIN tour_foreign_residence
ON (tour_foreign.id = tour_foreign_residence.relation)
INNER JOIN tour_foreign_airline
ON (tour_foreign.id = tour_foreign_airline.relation)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM