php - Add WHERE to PDO query if checkbox is checked -
i have mysql query pdo:
$ac_term = "%".$_get['term']."%"; $query = "select * table name :term"; $query .= $filterquery; $result = $conn->prepare($query); $result->bindvalue(":term",$ac_term); $result->execute();
i'm using autocomplete jquery code "term".
$('#input').autocomplete({ minlength: 2, source: function (request, response) { $.ajax({ url: 'suggest_zip.php', type: "post", data: { term: request.term, filter: '1' }, success: function (data) { response(data); } }); } })
if @ first block of code, can see tried $query .= $filerquery. $filterquery defined here:
$filter = "%".$_get['filter']."%"; if($filter = '1'){ $filterquery = 'where allowed = 1'; } else{ $filterquery = 'where allowed = 1 or allowed = 0'; }
so want search database records allowed = 1 when jquery variable filter = 1. else should search every record (it's either 1 or 0).
your appreciated!
change ajax request url to
$.ajax({ url: 'suggest_zip.php?filter=' + ($('#your_checkbox_selector').is(':checked') ? 1 : 0 ), //...
also, fix php condition
//this assignment , it's evaluated true (since equal 1) if($filter = '1'){
hope helps
Comments
Post a Comment