我无法在CodeIgniter查询上转换我的SQL查询(例如$ this-> db-> where等)我有两个左联接的SQL查询,也许是一个问题?请帮助!
这是我的常规查询:
SELECT * FROM ip_client left join ip_client_service ON (ip_client.client_id=ip_client_service.client_id) left join ip_product ON (ip_client_service.product_id=ip_product.product_id) WHERE ip_client_service.status='1'"
这是我在CodeIgniter中的尝试,但不起作用:(
((我在表名前使用前缀ip_,所以我不能在代码点火器中使用此前缀)
$this->db->select('*');
$this->db->from('client');
$this->db->join('client_service', 'client_service.client_id = client.client_id', 'left');
$this->db->join('product', 'product.product_id = client_service.product_id', 'left');
$this->db->where('client_service.status !=', '0');
(之后$ this-> db-> get()但不起作用)
您可以使用此示例
$this->db->select('tbl_order.*,tbl_user.fullname');
$this->db->from('tbl_order');
$this->db->join('tbl_user', 'tbl_user.id = tbl_order.user_id','left');
$query = $this->db->get();
return $query->result();
您未指定要从哪个表中获取数据。如果您只想从client
表中获取,则可以使用,否则也可以对其他两个表使用select
$this->db->select('client.*');
$this->db->from('client');
$this->db->join('client_service', 'client_service.client_id = client.client_id', 'LEFT');
$this->db->join('product', 'product.product_id = client_service.product_id', 'LEFT');
$this->db->where('client_service.status !=', '0');