我是 codeigniter 的新手。我想创建一个搜索栏,用户在其中写入一些关键字,它将检查数据库中表的所有字段,然后显示相关结果。
这是我的视图代码:
<?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;?>
名称为 site 的控制器代码是
function search(){
$search_book = array (
$search= $this->input->post('search')
);
$this->users_model->user_search($search_book);
$this->dashboard();
控制器中查询结果
if ($query = $this->users_model->user_search())
{
$search['searches'] = $query;
}
$data = $search;
$this->load->view('dashboard', $data);
这里是型号代码:
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();
显示错误
遇到 PHP 错误
严重性:警告
消息:Users_model::user_search() 缺少参数 1,调用于 C:\xampp\htdocs\Pure_Logics 应用程序