In database I have tables like: table 1: users
id | sports_type | age_group |languages
1 1,2 1,2 1,2
2 1 1 1
table 2 sports :
id name
1 Athletics
2 Aerobics
table 3 languages:
id lang
1 English
2 Spanish
table 4 age_group:
id groups
1 adults
2 teenagers
In html:
<h5>sports</h5>
<?php foreach($all_sports as $row ) { ?>
<div class="checkbox"><label>
<input class="sport_type" type="checkbox" name="all_sports[]" id="sport_id" value="<?php echo $row->id;?>" > <?php echo $row->name;?></label></div> <?php } ?>
<h5>age groups</h5><?php foreach($age_groups as $row) { ?>
<div class="checkbox">
<label><input type="checkbox" name="age_group[]" id="age_group" value="<?php echo $row->id;?>"> <?php echo $row->groups;?></label>
</div> <?php } ?>
<h5>languages</h5><?php foreach($languages as $row) { ?>
<div class="checkbox">
<label><input type="checkbox" name="languages[]" id="languages" value="<?php echo $row->id;?>"> <?php echo $row->lang;?>
</label>
</div><?php } ?>
Ajax code $:
$(document).ready(function() {
$('input:checkbox[name="all_sports[]"]').change(function() {
var checked = $('.sport_type:checked').map(function() {
return this.value;
}).get().join(', ');
$.ajax({
url: "<?php echo site_url('show/filter_sport_data');?>",
dataType: "text",
data: {
sport_id: checked
},
type: 'POST',
success: function(data) {
if (data != "") {
$('#filter_div').html(data);
} else {
var add = ' <div class="coach_listing col-lg-12 col-md-12 col-sm-12 col-xs-12"><h3 style="color: #0067da;">No result Found </h3></div>';
$('#filter_div').html(add);
}
}
});
});
$('input:checkbox[name="age_group[]"]').change(function() {
var checked = $('#age_group:checked').map(function() {
return this.value;
}).get().join(', ');
$.ajax({
url: "<?php echo site_url('show/filter_age_group');?>",
dataType: "text",
data: {
age_group: checked
},
type: 'POST',
success: function(data) {
if (data != "") {
$('#filter_div').html(data);
} else {
var add = ' <div class="coach_listing col-lg-12 col-md-12 col-sm-12 col-xs-12"><h3 style="color: #0067da;">No result Found </h3></div>';
$('#filter_div').html(add);
}
}
});
});
$('input:checkbox[name="languages[]"]').change(function() {
var checked = $('#languages:checked').map(function() {
return this.value;
}).get().join(', ');
$.ajax({
url: "<?php echo site_url('show/filter_languages');?>",
dataType: "text",
data: {
languages: checked
},
type: 'POST',
success: function(data) {
if (data != "") {
$('#filter_div').html(data);
} else {
var add = ' <div class="coach_listing col-lg-12 col-md-12 col-sm-12 col-xs-12"><h3 style="color: #0067da;">No result Found </h3></div>';
$('#filter_div').html(add);
}
}
});
});
problem:
its give duplicate result. if i select sports id 1 and language 1 its fetch all sport_type and language in user table but its give two diffrent result for one user i want one result