-1
您好,我想在复选框笨过滤...但它显示无法正常输出......如果有人知道这个请尽量解决这个笨复选框过滤
这是我的控制器
<?php
class Check extends CI_Controller {
public function laptops(){
$this->load->model('check_m');
$filter = array(
'price' => $this->input->get('price'),
'name' =>$this->input->get('name')
);
$data['laptop'] = $this->check_m->laptops_m($filter);
// echo json_encode($data['laptop']);
$this->load->view('check_view',$data);
}
}
?>
型号:
<?php
class check_m extends CI_Model {
function laptops_m($filter = null){
$this->db->select('*')
->from('mobile_phones');
// $query = $this->db->get('laptop_notebook')->result();
// return $query;
if($filter['name']){
$this->db->where('name', $filter['name']);
}
if($filter['price']){
$this->db->where('price', $filter['price']);
}
$query = $this->db->get()->result();
return $query;
}
}
?>
查看
<input type="checkbox" name="name" value="acer" class="searcType">
<input type="checkbox" name="name" value="lenovo">
<input type="checkbox" name="price" value="1000">
<table>
<tbody>
<?php foreach ($laptop as $laptops_all) { ?>
<tr>
<td><p>Laptop <?php echo $laptops_all->name ?> </p></td>
</tr>
<?php } ?>
</tbody>
</table>
<script>
$('.searchType').click(function() {
alert($(this).attr('id')); //-->this will alert id of checked checkbox.
if(this.checked){
$.ajax({
url: localhost/code/check/laptops,
dataType: 'json',
success: function(data){
$.each(data, function(index, element) {
$("tbody").empty();
$("tbody").append("<tr><td>"+
"Laptop "+element.brand+""+
"</td></tr>");
});
}
});
}
});
</script>
在这里我要为过滤与复选框的项目......但我没有得到滤波输出....
我想笨过滤复选框..动态...我想要做的是...这是正确的代码...或任何修改? – chandu
你的问题不清楚。在复选框中点击你想过滤数据?对? 当匹配字符串使用like而不是where: $ this-> db-> like('name',$ filter ['name']); –
亚..我已经尝试在核心php ..没关系......但在codeigniter它,s不工作 – chandu