简体   繁体   English

ajax在php中搜索多个表联接

[英]ajax search for multiple table join in php

I am using ajax for search functionality. 我正在使用ajax进行搜索。 There are dependent multiple table join. 有依赖的多表联接。 I am not getting proper result.I want unique result for search.Below my code is given: 我没有得到正确的结果。我想要唯一的搜索结果。下面给出我的代码:

$this->db->distinct('table2.sname,table3.cname');
$this->db>select('table1.stname,table2.*,table3.*,table4.*,table5.*');
$this->db->from('table5');
$this->db->join('table1','table1.stid=table2.stid');
$this->db->join('table2','table2.sid=table3.sid');
$this->db->join('table3','table3.cid=table4.cid');
$this->db->join('table4','table4.tid=table5.tid');
$this->db->or_like("table1.stname",$keyword);
$this->db->or_like("table2.sname",$keyword);
$this->db->or_like("table3.cname",$keyword);
$this->db->or_like("table4.tname",$keyword);
$this->db->or_like("table5.stoname",$keyword);
$query = $this->db->get();

If you need the first rows form select then you could use limit(1) 如果您需要选择第一行表格,则可以使用limit(1)

<?php 

    $this->db->distinct('table2.sname,table3.cname');
     $this->db>select('table1.stname,table2.*,table3.*,table4.*,table5.*');
     $this->db->from('table5');
     $this->db->join('table1','table1.stid=table2.stid');
     $this->db->join('table2','table2.sid=table3.sid');
     $this->db->join('table3','table3.cid=table4.cid');
     $this->db->join('table4','table4.tid=table5.tid');
     $this->db->or_like("table1.stname",$keyword);
     $this->db->or_like("table2.sname",$keyword);
     $this->db->or_like("table3.cname",$keyword);
     $this->db->or_like("table4.tname",$keyword);
     $this->db->or_like("table5.stoname",$keyword);

    $this->db->limit(1);

     $query = $this->db->get();

?>

or if you need all query result the return the result() 或者如果您需要所有查询结果,则返回result()

<?php 

    $this->db->distinct('table2.sname,table3.cname');
     $this->db>select('table1.stname,table2.*,table3.*,table4.*,table5.*');
     $this->db->from('table5');
     $this->db->join('table1','table1.stid=table2.stid');
     $this->db->join('table2','table2.sid=table3.sid');
     $this->db->join('table3','table3.cid=table4.cid');
     $this->db->join('table4','table4.tid=table5.tid');
     $this->db->or_like("table1.stname",$keyword);
     $this->db->or_like("table2.sname",$keyword);
     $this->db->or_like("table3.cname",$keyword);
     $this->db->or_like("table4.tname",$keyword);
     $this->db->or_like("table5.stoname",$keyword);


     $query = $this->db->get();

     return $query->result();

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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