我试图建立我的搜索栏创建结果表通过两个表进行搜索时。
每个表(新鲜,盐)具有2列(ID和说明)。
if(isset($_REQUEST["term"])){
// Prepare a select statement
$term = $_REQUEST['term'];
$sql = "SELECT * FROM fresh WHERE
description LIKE '%{$term}%' or
sku like '%{$term}%'
union
SELECT * FROM marine WHERE
description LIKE '%{$term}%' or
sku like '%{$term}%'";
if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_term);
// Set parameters
$param_term = $_REQUEST["term"] . '%';
搜索条件可以像“霓虹灯鱼”任何事情,但搜索目前将查找字符串是,我想它来搜索由空格分隔的两个+不同的关键字,即使条件落后,如“利霓虹灯” 。
其与两个表使用that.i米只是给example.don't知道哪些表具有主键或仲有关。尝试这个:
$this->db->join('fresh', 'fresh.id = salt.freshid')
->select('fresh.*,salt.id');
//你可以使用salt.id从盐表中的所有领域,salt.name等。
$where = '';
if ($this->input->post('search')['value'] && $this->input->post('search')['value'] != '') {
$where = "(fresh.sku LIKE '%" . $this->input->post('search')['value'] . "%' OR saly.sku LIKE '%" . $this->input->post('search')['value']. "%')";
}
if ($where != '') {
$this->db->where($where);
}
$count = $this->db->get('salt')->num_rows();
if ($this->input->post('length') != '-1') {
$this->db->limit($this->input->post('length'), $this->input->post('start'));
}
$query = $this->db->get('salt')->result_array();
return [$query, $count];