本文介绍了使用join(codeigniter)从单个字段中检索并打印逗号分隔符之后的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,当使用codeigniter从mysql检索值。
我有一个表名任务,并且有一个字段assigneduserid
表格 - 任务:
标题| assigneduserid
-------------------------------------
1 |工作区| 23,21
表 - 用户
id | title
-----------------
23 | Ashish
21 | Ritesh
在assigneduserid字段中,该字段中有两个值为23,21。
我要打印这样的用户标题: Ashish,Ritesh 来自usertable使用assignuserid。
并且我想按 assigneduseid
以升序设置该值。
我试图在页面上使用echo
<$ p code><?php echo $ task_row-> usertitle;?>
上述代码只能打印 Ashish 。
但我想打印 Ashish,Ritesh
以下是我的模型。
function getTask($ id,$ is_master_admin)
{
$ this-& > select('workspace.title as workspacetitle,user.title as usertitle,task。*');
$ this-> db-> join(WORKSPACE,WORKSPACE。'.id ='。TASK。'.workspaceid','inner');
$ this-> db-> join(USER,USER。'.id ='。TASK。'.assigneduserid','inner');
$ this-> db-> from(TASK);
if(!$ is_master_admin){
$ this-> db-> where(USER。'.id',$ id);
}
$ this-> db->其中(TASK。'.tasktypeid','1');
$ query = $ this-> db-> get();
if($ query-> num_rows()> 0){
return $ query-> result();
} else {
return false;
}
}
感谢您的进阶
function getTask($ id,b)
$ is_master_admin)
{
$ this-> db-> select('task。*,workspace.title as workspacetitle,GROUP_CONCAT(user.title)AS usertitle,task.assigneduserid ,user.id',FALSE);
$ this-> db-> join(WORKSPACE,WORKSPACE。'.id ='。TASK。'.workspaceid','inner');
$ this-> db-> join(USER,(FIND_IN_SET(USER .id,TASK.assigneduserid)),'inner');
$ this-> db-> from(TASK);
$ this-> db-> group_by(task.id);
if(!$ is_master_admin)
{
$ this-> db->其中(FIND_IN_SET($ id,task.assigneduserid));
}
$ this-> db->其中(TASK。'.tasktypeid','1');
$ query = $ this-> db-> get();
if($ query-> num_rows()> 0){
return $ query-> result();
} else {
return false;
}
}
I have one problem while retrieveing value from mysql using codeigniter.
I have one table name task and in that there is one field of assigneduserid.
Table - Task:
id | title | assigneduserid
-------------------------------------
1 | Workspace | 23,21
Table - User
id | title
-----------------
23 | Ashish
21 | Ritesh
In assigneduserid field there are two values in that field that is 23,21.
I want to print both usertitle like this : Ashish,Ritesh from usertable using that assigneduserid.
And also i want to set that value in ascending order which are in assigneduseid
I am trying to print that record on page using echo like following
Following is Code Where i am printing:
<?php echo $task_row->usertitle;?>
Above code is printing only Ashish.
but i would like to print Ashish,Ritesh
following is my model.
function getTask($id, $is_master_admin)
{
$this->db->select('workspace.title as workspacetitle, user.title as usertitle,task.*');
$this->db->join(WORKSPACE, WORKSPACE . '.id = ' . TASK . '.workspaceid', 'inner');
$this->db->join(USER, USER . '.id = ' . TASK . '.assigneduserid', 'inner');
$this->db->from(TASK);
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;
}
}
Thank you in advanced
解决方案
use this
function getTask($id, $is_master_admin)
{
$this->db->select('task.*, workspace.title as workspacetitle, GROUP_CONCAT( user.title ) AS usertitle,task.assigneduserid,user.id',FALSE);
$this->db->join(WORKSPACE , WORKSPACE . '.id = ' . TASK . '.workspaceid', 'inner');
$this->db->join(USER,("FIND_IN_SET(USER .id , TASK.assigneduserid)"), 'inner');
$this->db->from(TASK);
$this->db->group_by("task.id");
if (!$is_master_admin)
{
$this->db->where ("FIND_IN_SET($id, task.assigneduserid)");
}
$this->db->where(TASK . '.tasktypeid', '1');
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result();
} else {
return false;
}
}
这篇关于使用join(codeigniter)从单个字段中检索并打印逗号分隔符之后的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!