i have 3 checkboxes and when i click on it, it should change the sql string and show me a new sql query.
my HTML code:
<div id="#check_article">
<input type="checkbox" value="Iphone">Iphone
<input type="checkbox" value="Samsung">Samsung
<input type="checkbox" value="Nokia">Nokia
</div>
my script:
var arr = [];
$('input[type=checkbox]').change(function () {
if ($(this).prop("checked")) {
var value = $(this).val();
arr.push(value);
}
else {
arr.splice($.inArray($(this).val(),arr),1);
}
var new_string = arr.toString();
console.log(new_string);
});
so when i click on the checkbox my console.log shows me the right value in string. when i uncheck the box it deletes me the value from the string.
now i have to pass it to the server with ajax.
$.ajax({
url:"query.php",
method:"POST",
data: {'qry':new_string},
success:function(data) {
('#result').html(data);
}
});
on php side ... i wolud like to search for a checked article with this
$sql = "SELECT * FROM Store WHERE Name LIKE 'mobilePhone' AND Article='....'
AND Article='....'" AND Article='....';
but i realized that i have to format my string. My string is right now : "Iphone,Nokia,Samsung"
but i need it to change to AND Article= 'Iphone' AND Article = 'Nokia' AND Article='Samsung'
is this a right way do to it like this or is there a better way ?
Aucun commentaire:
Enregistrer un commentaire