AJAX filter MySQL results using checkboxes
        Posted  
        
            by 
                keepitnang
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by keepitnang
        
        
        
        Published on 2012-06-29T15:11:57Z
        Indexed on 
            2012/06/29
            15:15 UTC
        
        
        Read the original article
        Hit count: 271
        
I'm attempting to get to grips with displaying filterable MySQL data within a PHP page based on user checkbox selections. I have a database of domain names and the dates on which these will require renewal as per Nominet DAC information and I can get unfiltered data to display, but filtering results by domain extensions is proving tricky for me to accomplish. I should point out at this stage that I am a serious newcomer to many of the ideas I am trying to learn to work with here, so please be gentle. I have tried following some other articles on here also, but no dice.
I have the following so far:
HTML
<input type="checkbox" class="extensions" name="extensions" value=".co.uk">.co.uk</input>
<input type="checkbox" class="extensions" name="extensions" value=".org.uk">.org.uk</input>
Script
$('.extensions').live('click', function() {
var all_boxes = $('.extensions');
var all_boxes_values = [];
var i = 0;
for (var i; i < all_boxes.length; i++) {
    if (all_boxes[i].checked) {
        all_boxes_values.push(all_boxes[i].value)
    }
}   
var all_boxes_values_clean = all_boxes_values.join(", ");
console.log(all_boxes_values_clean);
$.get("sql-test.php", {q: all_boxes_values_clean},
function(result) {
$("div#output").html(result);
}   
    )});     
PHP
$g = $_GET['q'];
$extensionsql="";
$extension=1;
if(isset($g))   {
$extension=1;
$param = "" . str_replace(",", "','", $_GET['q']) . "";
}
And that's as far as I have gotten with my limited ability. What I would like to do next is search the column domainName for a string match and return the appropriate results to the user. Something to mimic something like the following but I'm not sure how to achieve it. Any help would be much appreciated:
SELECT * FROM `refresh` WHERE `domainName` LIKE '%.co.uk%' AND renewalDate LIKE '%2012-06-30%' ORDER BY `domainName` ASC  
Thanks
© Stack Overflow or respective owner