hi i want to checkbox filtering in codeigniter... but it shows not correctly output...if anyone knows this please try to solve this
this is my controller
<?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);
}
}
?>
Model:
<?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;
}
}
?>
View
<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>
Here i want to filter the items with checkboxes... but i didn't get filtering output....