I am new in codeigniter. I want to create a search bar where user write some keyword and it will check in all fields of table in database and then show relative result.
Here is my code of View:
<?php
echo '<h2>Search Books</h2>';
echo form_open('site/search');?>
<p>
<label for="title"> Title:</label>
<input type="text" placeholder="Search" name="search" size="50%">
</p>
<input type="submit" value="Submit"/>
<?php echo form_close(); ?>
<!--Here will be Search Result-->
<?php if (isset($searches)): foreach($searches as $search):?>
<h4><?php echo "   ";
echo $search->book_name;
echo "   "; ?></h4>
<?php endforeach; ?>
<?php else: ?>
No Book Found
<?php endif;?>
And the controller code with name site is
function search(){
$search_book = array (
$search= $this->input->post('search')
);
$this->users_model->user_search($search_book);
$this->dashboard();
Query Result in Controller
if ($query = $this->users_model->user_search())
{
$search['searches'] = $query;
}
$data = $search;
$this->load->view('dashboard', $data);
Here is Model Code:
function user_search($search_book){
$query = $this->db->like('book_name', $search_book);
$this->db->or_like('author', $search_book);
$this->db->or_like('date', $search_book);
$this->db->get('books');
return $query->result();
Error Shown
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Users_model::user_search(), called in C:\xampp\htdocs\Pure_Logics\application\controllers\site.php on line 28 and defined
Filename: models/users_model.php
Line Number: 26
Backtrace:
File: C:\xampp\htdocs\Pure_Logics\application\models\users_model.php Line: 26 Function: _error_handler
File: C:\xampp\htdocs\Pure_Logics\application\controllers\site.php Line: 28 Function: user_search
File: C:\xampp\htdocs\Pure_Logics\index.php Line: 315 Function: require_once
Missing argument in method calling
$this->users_model->user_search()
change to
if ($query = $this->users_model->user_search($this->input->post('search')))
{
$search['searches'] = $query;
}
Model:
function user_search($search_book){
$this->db->like('book_name', $search_book);
$this->db->or_like('author', $search_book);
$this->db->or_like('date', $search_book);
$query = $this->db->get('books');
return $query->result();
}
Controller:
function search(){
$this->dashboard();
$data['searches'] =array();
if ($query = $this->users_model->user_search($this->input->post('search')))
{
$data['searches'] = $query;
}
$this->load->view('dashboard', $data);
}
1) You calling method without argument . But your defined method with argument in model .