简体   繁体   中英

Not work WHERE IN sql INNER JOIN?

I want WHERE data select with $find, but it(WHERE) not work in following query and my output is There is not , how fix it?

$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';
}

You have an extra comma before the WHERE (after tour_foreign_airline.relation).

Edit: I see you fixed it now, but the JOIN still looks wrong. Try this:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM