下面是我的代码。 型号。
function get_search_conv()
{
$match = $this->input->post('search');
$this->db->like('TextDecoded',$match);
$query = $this->db->get('inbox');
return $query->result();
}
它适用于一张表,但如何在表“inbox2”中搜索 textDecoded? 我尝试过加入工会或加入,但仍然不起作用。有人可以帮助我吗? 谢谢
最佳答案
你可以这样做
$sql="select * from inbox in1, inbox2 in2
where in1.TextDecoded like '%".$match."%'
or in2.TextDecoded like '%".$match."%'";
$query = $this->db->query($sql);
return $query->result();
另一种可能的解决方案是
function get_search_conv()
{
$match = $this->input->post('search');
$this->db->like('TextDecoded',$match);
$this->db->or_like('TextDecoded',$match);
$this->db->from('inbox,inbox2');
$query = $this->db->get();
return $query->result();
}
这是您的另一个答案。避免使用 Active Record 执行此操作,因为您必须将 DB_active_rec.php 中的函数 _compile_select() 和 _reset_select() 的访问修饰符更改为 public。这不是一个好主意
$sql = "SELECT TextDecoded FROM inbox where TextDecoded like '%".$match."%'
UNION
SELECT TextDecoded FROM inbox2 where TextDecoded like '%".$match."%'"
$query = $this->db->query($sql);
return $query->result();
关于mysql - 我如何从两个不同的表中搜索数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23623855/