Codeigniter 活动记录帮助或 mysql 帮助
我有这个语法从数据库中获取一些数据,我使用codeigniter的活动记录,
$this->db->select('job_id, jobs.employer_id, company_job_id, like_job_id, logo, company_name')
->from('jobs')
->join('company_likes', 'company_likes.like_job_id = jobs.job_id', 'left')
->join('company_views', 'company_views.company_job_id = jobs.job_id', 'left')
->join('employers', 'employers.employer_id = jobs.employer_id', 'left');
$query = $this->db->get();
return $query->result_array();
不,这应该返回1个结果,但是,它返回4条记录,因为这是company_views表中的记录数,我想要实现的是我得到了该雇主数据库中的视图数量,但我只想使用一个查询来完成此操作。
目前,此查询用于向用户获取雇主详细信息,但我还想反馈雇主被查看的次数。
I have this syntax for grabbing some data from database, I using codeigniter's active record,
$this->db->select('job_id, jobs.employer_id, company_job_id, like_job_id, logo, company_name')
->from('jobs')
->join('company_likes', 'company_likes.like_job_id = jobs.job_id', 'left')
->join('company_views', 'company_views.company_job_id = jobs.job_id', 'left')
->join('employers', 'employers.employer_id = jobs.employer_id', 'left');
$query = $this->db->get();
return $query->result_array();
No this should be return 1 result however, it is returning 4 records as that is the number of records in the company_views table, what I am wanting to achieve is that I get returned the number of views in the databsae for that employer, but I only want to do it using one query.
Currently this query is used to get the employer details to the user, but I also want to feed back how many times the emloyer has been viewed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加
$this->db->group_by('company_views.company_job_id')
try adding
$this->db->group_by('company_views.company_job_id')