我做了这样的搜索,但它没有在文本框中取过值,任何人都可以帮我解决这个问题..谢谢进展........我的模型查询是正确的或任何错误是还有......
如果我输入搜索字词,它会重定向到搜索结果页面但显示空白结果.......并且它说为foreach提供的无效参数()
如果我打印last_query()
,它显示如下......
SELECT * FROM (`clients`) WHERE `clientName` LIKE '%%'
这是我的控制器:
class Client extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model("client_model");
$this->load->model("interview_model");
$this->load->model("candidate_model");
$this->load->model("requirement_model");
}
function search()
{
$search_term = $this->input->post('search');
$data['query'] = $this->client_model->search_client($search_term);
echo "<pre>"; print_R($this->db->last_query()); exit;
$data['page_title'] = "Search Results";
$this->layout->view("client/search",$data);
}
}
型号:
function search_client($search_term)
{
$this->db->select('*');
$this->db->from('clients');
$this->db->like('clientName',$search_term);
// Execute the query.
$query = $this->db->get();
// Return the results.
return $query->result_array();
}
这是index.php(View)中的表单:
<form action="<?php base_url();?>client/search">
<input type="text" name="search" id="search" style="width:180px" placeholder="Search here..." />
<input type="submit" value="Search" name="submit" class="btn btn-primary btn-sm" /></form>
这是search.php(查看):
<?php foreach($query as $client){ ?>
<tr>
<td><?php echo $client->clientName;?></td>
<td><?php echo $client->clientSName; ?></td></td>
<td>
<?php } ?>
答案 0 :(得分:0)
更改此行:
<form method="POST" action="<?php base_url();?>client/search">
到此:
<form action="<?php echo base_url();?>client/search">
并尝试以下approch:
function search_client($search_term){
$this->db->select('*');
$this->db->from('clients');
$this->db->like('clientName',$search_term);
// Execute the query.
$query = $this->db->get();
if($query->num_rows()>0)
return $query->result();
else
return false;
}