drm16022 2015-09-15 12:26
浏览 24

如何在这里多次搜索代码

This is the code work fine but only for one column search which is user in below code, but need to search more than one column like password , email

controller

public function index()
{
    $this->input->post('search'); //this is drag from view table *name=search*
    $search=$this->input->post('search');
    $data['user']=$this->usermodel->searchUser($search);
    $this->load->view('user',$data);
}

model

public function searchUser($search=null)
{
    $this->db->select("*");
    $this->db->from("tbl_user");
    $this->db->where("user",$search); //user is one column of table *tbl_user*
    $query=$this->db->get();
    if($query->num_rows()>0)
    {
        $result=$query->result_array();
        return $result;
    } else {
        return false;
    }
}
  • 写回答

1条回答 默认 最新

  • dsfdsf21321 2015-09-15 12:32
    关注

    You can use multiple where like this

    $this->db->where('email',$email);
    $this->db->where('password',$password);
    

    You can use an array and pass the array. Associative array method:

    $array = array('user' => $user, 'email' => $email, 'password' => $password);
    
    $this->db->where($array); 
    
    // Produces: WHERE user = 'Joe' AND email = 'joe@example.com' AND password = 'password'
    

    Please check CI Query Builder Class for details

    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了