doudouchan5830 2018-12-18 09:30
浏览 28
已采纳

如何根据在MULTISELECT上选择的数据在codeigniter中循环OR WHERE

I want to make a data filter feature using the MULTISELECT category where the data that appears is in accordance with the list of categories selected on the filter. So, I plan to loop the OR WHERE command according to the list of categories chosen by the user. OR WHERE has been successfully loop according to the number of categories chosen, but not for the ID. And show error like this "Array to string conversion"

What is the cause and what is the solution? Thank you


My Controller

$sort = $this->input->post('sort');
$category = $this->input->post("get_kategori_acara_css[]");
$interest = $this->input->post("get_interest_acara_css[]");

/* eksekusi library pagination ke model penampilan data */
if (!empty($sort) || !empty ($category) || !empty ($interest))
{ 
  $this->data['list_acara'] = $this->Acara_model->get_filtered($sort, $category, $interest, $config['per_page'], $dari);
}
else 
{
  $this->data['list_acara'] = $this->Acara_model->get_all_arsip();
}

MY MODEL

public function get_filtered ($sort, $category, $interest) {
$this->db->join('kategori', 'acara.id_kategori = kategori.id_kategori');
$this->db->join('interest_acara ', 'acara.id_acara  = interest_acara.id_acara', 'left');
$this->db->join('hits_acara  ', 'acara.judul_seo = hits_acara.judul_seo', 'left');
$this->db->where('publish','Ya');
$this->db->group_by('acara.judul_seo');
if(!empty($sort AND empty($category) AND empty($interest))) 
{
  $this->db->order_by($sort, $this->order);
}
elseif(!empty($sort) AND !empty($category) AND empty($interest)) 
{
  foreach ($category as $value) {
    $this->db->or_where('acara.id_kategori', $value->id_kategori);
  }
}
return $this->db->get($this->table)->result();
}

Shown Error

My Multiselect Feature

  • 写回答

1条回答 默认 最新

  • duanbei8904 2018-12-18 17:15
    关注

    The problem is the use of $value->id_kategori in the foreach ($category as $value) loop.

    The variable $value is not an object so trying to get the value of the property, i.e. $value->id_kategori makes no sense.

    $category is a simple indexed array of values e.g.

    array('0'=>'123', '1'=>'456', '2'=>'789')
    

    I think all you need to do is change this

    $this->db->or_where('acara.id_kategori', $value->id_kategori);
    

    to this

    $this->db->or_where('acara.id_kategori', $value);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因