不工作在sql INNER JOIN中?

时间:2011-10-18 16:34:04

标签: php mysql codeigniter

我希望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';
}

1 个答案:

答案 0 :(得分:2)

您在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)