sql INNER JOIN 中的位置不起作用?

发布于 2024-12-10 17:41:04 字数 917 浏览 1 评论 0原文

我想要使​​用 $find 选择 WHERE 数据,但它(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';
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半透明的墙 2024-12-17 17:41:04

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文