codeigniter-error on search and display data from database

731 Views Asked by At

When I click on search button the data is being sent, I have verified that but I keep getting this error as soon as I click the button now:

A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Admin::select()

Filename: controllers/Admin.php

Line Number: 52

Line number 52 is the start if the controller code.

View:

<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>

Controller:

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');
    }
}  

}

Model:

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

There are 1 best solutions below

8
On BEST ANSWER

Your where condition is wrong in model file

Model

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;
    }
}

Controller

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');
    }
}  
}