Php codeigniter中具有多个条件的SQL查询

Php codeigniter中具有多个条件的SQL查询,php,mysql,codeigniter,Php,Mysql,Codeigniter,我一直在尝试基于“category”(应该是Where子句)获取记录,但很少有其他限制,如下所示。请指导我在以下代码中插入where子句的位置,即where category=$category $this->db->select('*'); $this->db->from('proj_item_details','proj_item_images'); $this->db->join('proj_item_images', 'proj_item_images

我一直在尝试基于“category”(应该是Where子句)获取记录,但很少有其他限制,如下所示。请指导我在以下代码中插入where子句的位置,即where category=$category

$this->db->select('*');
$this->db->from('proj_item_details','proj_item_images');
$this->db->join('proj_item_images', 'proj_item_images.proj_id=proj_item_details.proj_id');
$this->db->like('proj_item_title',$params['search']['keywords']);
$this->db->order_by('proj_item_title',$params['search']['sortBy']);
$this->db->limit($params['limit'],$params['start']);

将这一行添加到代码中-

$this->db->where('proj_item_details.category', $category);
示例-

$this->db->select('*');
$this->db->from('proj_item_details','proj_item_images');
$this->db->where('proj_item_details.category', $category);
$this->db->join('proj_item_images', 'proj_item_images.proj_id=proj_item_details.proj_id');
$this->db->like('proj_item_title',$params['search']['keywords']);
$this->db->order_by('proj_item_title',$params['search']['sortBy']);
$this->db->limit($params['limit'],$params['start']);

将这一行添加到代码中-

$this->db->where('proj_item_details.category', $category);
示例-

$this->db->select('*');
$this->db->from('proj_item_details','proj_item_images');
$this->db->where('proj_item_details.category', $category);
$this->db->join('proj_item_images', 'proj_item_images.proj_id=proj_item_details.proj_id');
$this->db->like('proj_item_title',$params['search']['keywords']);
$this->db->order_by('proj_item_title',$params['search']['sortBy']);
$this->db->limit($params['limit'],$params['start']);
像这样试试

1.无需在
from
语句中定义两个表

2.在加入两个表后放置where条件

3.在
order\u by
like
语句中,正确定义

$this->db->select('*');
$this->db->from('proj_item_details');//only one table name here
$this->db->join('proj_item_images', 'proj_item_details.proj_id=proj_item_images.proj_id');
$this->db->where('proj_item_details.category', $category);//where condition here

$this->db->like('proj_item_details.proj_item_title',$params['search']['keywords']);//define table_name.column_name
$this->db->order_by('proj_item_details.proj_item_title',$params['search']['sortBy']);//define table_name.column_name
$this->db->limit($params['limit'],$params['start']);
像这样试试

1.无需在
from
语句中定义两个表

2.在加入两个表后放置where条件

3.在
order\u by
like
语句中,正确定义

$this->db->select('*');
$this->db->from('proj_item_details');//only one table name here
$this->db->join('proj_item_images', 'proj_item_details.proj_id=proj_item_images.proj_id');
$this->db->where('proj_item_details.category', $category);//where condition here

$this->db->like('proj_item_details.proj_item_title',$params['search']['keywords']);//define table_name.column_name
$this->db->order_by('proj_item_details.proj_item_title',$params['search']['sortBy']);//define table_name.column_name
$this->db->limit($params['limit'],$params['start']);

当然,在我的例子中,proj_item_details.category是不必要的,尽管当有多个可能具有相同字段名的表时,避免混淆是一种很好的做法。感谢lotSure man..proj_item_details.category在我的情况下是不必要的,尽管当有多个可能具有相同字段名的表时,避免混淆是一种很好的做法。非常感谢。很高兴帮助你。祝你好运。很高兴帮助你。祝你好运。