Php 如果数据存储为内爆,我们如何使用where条件
这里我的桌子看起来像这样Php 如果数据存储为内爆,我们如何使用where条件,php,codeigniter-3,Php,Codeigniter 3,这里我的桌子看起来像这样 public function get_location_departments() { $d = $_POST['location']; $data['departments'] = $this->Hospital_model->get_location_departments($d); $this->load->view('frontend/ajax_get_departments',$data); } public fu
public function get_location_departments()
{
$d = $_POST['location'];
$data['departments'] = $this->Hospital_model->get_location_departments($d);
$this->load->view('frontend/ajax_get_departments',$data);
}
public function get_location_departments($d)
{
$this->db->where_in('location_id',$d);
$query=$this->db->get('department')->result();
return $query;
}
如果location\u id
是3
,我想得到所有的科室,这意味着如果使用location id3
,我需要得到cardiology
和hair
的科室名称,这样我就完成了这样的代码
我的控制器
如下所示
public function get_location_departments()
{
$d = $_POST['location'];
$data['departments'] = $this->Hospital_model->get_location_departments($d);
$this->load->view('frontend/ajax_get_departments',$data);
}
public function get_location_departments($d)
{
$this->db->where_in('location_id',$d);
$query=$this->db->get('department')->result();
return $query;
}
我的型号
如下所示
public function get_location_departments()
{
$d = $_POST['location'];
$data['departments'] = $this->Hospital_model->get_location_departments($d);
$this->load->view('frontend/ajax_get_departments',$data);
}
public function get_location_departments($d)
{
$this->db->where_in('location_id',$d);
$query=$this->db->get('department')->result();
return $query;
}
请帮我解决我的问题希望这能帮助你: 您必须首先进行查询,以获取
部门
,并使用分解
您的模型get\u location\u departments
方法应如下所示:
public function get_location_departments($d)
{
if (! empty($d))
{
$query = $this->db->get('department');
if ($query->num_rows() > 0 )
{
foreach ($query->result() as $location)
{
$location_ids = explode(',',$location->location_id);
if (in_array($d, $location_ids))
{
$data[] = $location;
}
}
}
return $data;
//print_r($data);
}
}
希望这对您有所帮助: 您必须首先进行查询,以获取
部门
,并使用分解
您的模型get\u location\u departments
方法应如下所示:
public function get_location_departments($d)
{
if (! empty($d))
{
$query = $this->db->get('department');
if ($query->num_rows() > 0 )
{
foreach ($query->result() as $location)
{
$location_ids = explode(',',$location->location_id);
if (in_array($d, $location_ids))
{
$data[] = $location;
}
}
}
return $data;
//print_r($data);
}
}
我想正确的答案是什么
public function get_location_departments($d)
{
$query = $this->db
->where('FIND_IN_SET('.$this->db->escape($d).', location_id)', NULL, false)
->get('department')
->result();
return $query;
}
为此,有一个名为FIND_IN_SET
的函数。您可以在下面的mysql文档中找到它
我想正确的答案是什么
public function get_location_departments($d)
{
$query = $this->db
->where('FIND_IN_SET('.$this->db->escape($d).', location_id)', NULL, false)
->get('department')
->result();
return $query;
}
为此,有一个名为FIND_IN_SET
的函数。您可以在下面的mysql文档中找到它
您是否只对获取第一个数字感兴趣?如果是这样的话,为什么不使用LIKE?可能的副本?您是否只对获取第一个数字感兴趣?如果是这样,为什么不使用LIKE?