使用codeigniter从mysql中检索值时遇到一个问题。
我有一个表名任务,其中有一个assigneduserid字段。
表格 - 任务:
id | title | Title | assigneduserid
--------------------------------------------------------
1 | Workspace |PMS | 23,21
表格 - 用户
id | title
-----------------
23 | Ashish
21 | Ritesh
在assigneduserid字段中,该字段中有两个值为23,21。
我想在用户登录中显示任务标题。 但它只显示给Ashish登录。 我怎么解决呢?
以下是我的模特: -
function getTask($id, $is_master_admin) {
$this->db->select('task.*, workspace.title as workspacetitle, user.title as usertitle');
$this->db->join(WORKSPACE, WORKSPACE . '.id = ' . TASK . '.workspaceid', 'inner');
$this->db->join(USER, USER . '.id = ' . TASK . '.userid', 'inner');
$this->db->from(TASK);
$this->db->group_by('task.id');
if (!$is_master_admin) {
$this->db->where(USER . '.id', $id);
}
$this->db->where(TASK . '.tasktypeid', '1');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result();
} else {
return false;
}
}
任何人都可以帮忙吗?
答案 0 :(得分:0)
function getTask($id, $is_master_admin) {
$data= $this->db->group_by('task.id')->get('task')->result();//check what value your getting in data and then use foreach and select the user from the user table
foreach($data as $value):
$array= $this->db->where('id',$value->id)->get('user')->result();
endforeach;
}
答案 1 :(得分:0)
尝试,尚未检查,
$tsql = " SELECT task.*, workspace.title AS workspacetitle, GROUP_CONCAT(user.title ORDER BY id) AS usertitle ".
" INNER JOIN ". WORKSPACE ." ON ". WORKSPACE .".id = " . TASK . ".workspaceid ".
" INNER JOIN USER ON FIND_IN_SET(".USER . ".id, ". TASK .".assigneduserid ) > 0 ".
" FROM ". TASK ;
if (!$is_master_admin) {
$tsql .= " WHERE ". USER . ".id =". $id;
}
$tsql .= " WHERE ". TASK . ".tasktypeid =1 ";
$tsql .= " GROUP BY ". TASK .".id ";
$query = $this->db->query($tsql);