由于我在DB中使用逗号分隔值,每个人都建议我对表进行规范化,所以我将表格规范化,现在我的表格看起来像这样
tuitor table
tuitor_id | name | mobile |etc
1 | xyz |14562547|anyinputs
2 |abc |47545875|text
3 |abd |47854874|yyy
now my normalized table is tuitor_keyword
tuitor_keyword_id | id_tuitor | id_keyword
1 | 1 |123
2 | 1 |124
3 | 2 |123
4 | 2 |155
5 | 1 |187
在检索任何tuitor时,我想要逗号中的关键字,例如id_tuitor = 1,它应该是123,124
this is the query what i am using
$this->db->select('*')->from('tuitor');
$this->db->join('tuitor_keyword','tuitor.tuitor_id = tuitor_keyword.id_tuitor','left');
$query=$this->db->get();
return $result = $query->result_array();
它正在为tuitor_keyword_id创建新数组我应该怎么做请纠正我我知道我犯了很多错误
答案 0 :(得分:0)
CONCAT_GROUP是您的解决方案:
$this->db->query('SELECT id_tuitor, CONCAT_GROUP(id_keyword) AS gr FROM tuitor_keyword GROUP BY id_tuitor');
或:
$this->db->select('id_tuitor, CONCAT_GROUP(id_keyword) AS gr', false)->from('tuitor_keyword')->group_by('id_tuitor');