这是我的模特:
function get_search() {
$match = $this->input->post('search');
$this->db->like('p_category',$match);
$this->db->or_like('p_place',$match);
$this->db->or_like('p_price',$match);
$query = $this->db->get('tbl_property');
if($query->num_rows() > 0)
return $query->result();
else
return FALSE;
}
这是我的观点:
<?php
foreach($query as $pack_details):
?>
<table class="table table-hover table-bordered">
<?php echo $pack_details->p_title?>
</table>
<?php
endforeach;?>
想要搜索并仅显示我搜索过的结果。
答案 0 :(得分:0)
这是我的旧版本,但您可以将其改编为您的版本。您的表单将帖子发送给控制器。变量$ art是搜索项。变量$ num是结果的数量。 jquery将表单发送到文章类search_results
控制器
public function seek()
{
// this is the artist search display
$art = html_escape(trim($this->input->post('art')));
$this->db->like('artist', $art);
$this->db->select('artist, song, album, mix_name');
$query = $this->db->get('podcasts');
$num = $query->num_rows();
echo "<h3>We found $num $art song's</h3>";
if($query->num_rows() > 0) {
foreach ($query->result() as $row) {
echo "<li class='search_list'>Song: $row->song <br> Album: $row->album <br> Podcast: $row->mix_name</li> ";
}
}else {
echo "You searched for $art, Please check your spelling, or ensure the artists name is complete";
}
}
如果您希望搜索显示在同一页面上,请使用Jquery
$(function () {
"use strict";
$("#search").submit(function () {
var data = $('#search').serialize();
//alert(data); return false;
$.ajax({
url: "/display/seek",
data: data,
type: "POST",
success: function (msg) {
$('article.search_results').html(msg).show();
}
});
return false;
});
});
查看很简单。请参阅jquery中的最后一行
<article class="search_results"></article>