【发布时间】:2014-03-07 10:04:33
【问题描述】:
大家好,我正在使用 CI 框架,我已经写了一个查询...如下
public function home_lastest_company()
{
$this->db->select('c.id as company_id,c.name as company,c.type,cp.company_logo,it.title as industry,jc.title as category');
$this->db->from(JB_COMPANY_TABLE . ' c');
$this->db->join(JB_COMPANY_PROFILE_TABLE . ' cp', 'c.id=cp.jb_company_id', 'left');
$this->db->join(JB_INDUSTRY_TYPE . ' it', 'c.industry_id = it.id', 'LEFT');
$this->db->join(JB_CATEGORY . ' jc', 'c.category_id = jc.id', 'LEFT');
$this->db->where('c.visibility', '1');
$this->db->where('c.status', '1');
$this->db->order_by('c.created_date', 'desc');
$objquery = $this->db->get();
return $objquery->result_array();
}
对此的 sql 查询是
SELECT `c`.`id` as company_id, `c`.`name` as company, `c`.`type`, `cp`.`company_logo`, `it`.`title` as industry, `jc`.`title` as category FROM (`jb_company` c)
LEFT JOIN `jb_company_profile` cp ON `c`.`id`=`cp`.`jb_company_id`
LEFT JOIN `jb_industry_type` it ON `c`.`industry_id` = `it`.`id`
LEFT JOIN `jb_category` jc ON `c`.`category_id` = `jc`.`id`
WHERE `c`.`visibility` = '1' AND `c`.`status` = '1' ORDER BY `c`.`created_date` desc
我得到一个这样的数组
Array
(
[0] => Array
(
[company_id] => 14
[company] => Tech Hive
[type] => 0
[company_logo] => clogo8.png
[industry] => BROADCASTING
[category] => Electronics
)
[1] => Array
(
[company_id] => 13
[company] => WadeTech
[type] => 0
[company_logo] => download.jpg
[industry] => INFORMATION TECHNOLOGY
[category] => Information Technology
)
[2] => Array
(
[company_id] => 16
[company] => Reliance
[type] => 0
[company_logo] => reliance.jpg
[industry] => ELECTRONICS
[category] => Electronics
)
[3] => Array
(
[company_id] => 12
[company] => AVIVA
[type] => 1
[company_logo] => aviva.jpg
[industry] => CONSULTING
[category] => Management
)
[4] => Array
(
[company_id] => 11
[company] => Apple
[type] => 2
[company_logo] => apple10.jpg
[industry] => Agriculture
[category] => Information Technology
)
[5] => Array
(
[company_id] => 9
[company] => Samsung
[type] => 1
[company_logo] => samsung.jpg
[industry] => ELECTRONICS
[category] => Information Technology
)
)
实际上,除了上面显示的数据之外,还有更多的数据....现在我想要的是一个查询,在该查询中,我根据字段类型限制了数据。例如我想要 20 行类型 0 20 行类型 1, 20 行类型 2
【问题讨论】:
标签: mysql sql codeigniter