codeigniter-error搜索和显示数据库中的数据

时间:2015-06-09 13:31:40

标签: php codeigniter

当我点击搜索按钮时,数据正在发送,我已经验证了但是 我现在点击按钮后立即收到此错误:

  

遇到PHP错误

     

严重性:警告

     

消息:缺少Admin :: select()

的参数1      

文件名:controllers / Admin.php

     

行号:52

如果控制器代码,则行号52是开始。

查看:

<form action="#" class="login-wrapper" method="get">
    <div class="span12" align="center">
     <input class="input span12 password" type="text" name="search" placeholder="search by name">
    <div class="actions">
     <input class="btn btn-danger" type="submit" name="sub" value="search now">
    </div>
    </div >
</form>

控制器:

public function select ($search){

$this->load->model('Login_model');

if(isset($_GET ['search']) && !empty($_GET['search'])) {

    $search= $_GET[ 'search'];
    $this->load->model('Login_model');
    $result=$this->Login_model->selectorganizer($search)''

    if($result)
    {
        $data['result']=$result;
        $this->load->view('admin/show/org', $data);
    }
    else
    {
        redirect('admin/show');
    }
}  

}

型号:

public function selectorganizer ($search) {
    $condition = "search = '" . $search . "'";
    $this->db->select('*');
    $this->db->from('organizer');
    $this->db->where($condition);
    $query = $this->db->get();
    return $result = $query->result();
}          

1 个答案:

答案 0 :(得分:2)

模型文件中的条件错误

<强>模型

public function selectorganizer($search) {
    $this->db->select('*');
    $this->db->from('organizer');
    $this->db->where('name', $search);// chnage your column name here
    $query = $this->db->get();
    $num = $query->num_rows();
    if ($num > 0) {
        return $result = $query->result();
    } else {
        return FALSE;
    }
}

<强>控制器

public function select (){// no need to pass agrument

$this->load->model('Login_model');

if(isset($_GET['search']) && !empty($_GET['search'])) {// remove space between $_GET and search

    $search= $_GET['search'];
    $this->load->model('Login_model');
    $result=$this->Login_model->selectorganizer($search);//semicolumn here

    if($result)
    {
        $data['result']=$result;
        $this->load->view('admin/show/org', $data);
    }
    else
    {
        redirect('admin/show');
    }
}  
}