-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