Currently I have one php file createNewForm.php. In it, I have a list of checkboxes, when I check each checkbox, I want the sql query in my php file (createNewForm.php) to repopulate a list.
So lets say I have checkboxes 'Animals', 'Plants', 'Food' and I check 'Animals' then list will populate with Chicken, Cow, Dog. If I check 'Food', it will include 'Chicken','Cow','Dog','Pizza' where 'Chicken' is in both Animals and Food (sorry if you are vegetarian haha).
I am not so much worried about the SQL side of things as that part is working.
Below is my javascript for sending my checked values (Animals,Plants,Food) to itself:
createNewForm.php (javascript portion)
var $checkedSites = [];
var $checkedSitesString = '';
$(document).ready(function() {
$('.checkedSites').change(function() {
if($(this).is(':checked')) {
$checkedSites.push($(this).val());
}
else
{
$checkedSites.splice($.inArray($(this).val(),$checkedSites),1);
}
$checkedSitesString = "'" + $checkedSites.join("','") +"'";
var sitesChosen = 'sitesChosen='+$checkedSitesString;
$.ajax({
type: "GET",
url: "createNewForm.php",
data: sitesChosen,
cache: false,
success: function(result){
alert(result);
}
});
});
});
createNewForm.php (php portion)
<?php
if (isset($_GET["sitesChosen"]) && !empty($_GET["sitesChosen"]) && $_GET["sitesChosen"] != '') { //Checks if action value exists
$sitesChosen = $_GET["sitesChosen"];
$productTypePopulationSQL = "SELECT distinct productname
FROM productType
WHERE active = 1
and sitetypeid in (".$sitesChosen.");";
}
else
{
$productTypePopulationSQL = "SELECT distinct productname
FROM productType
WHERE active = 1;
";
}
?>
Currently the output, as the code is written will give me the complete set regardless of which one is checked for sanity purposes. I have also echo'ed the result from my php when it is set through Javascript and my SQL statement is revised to what I want it to be but it also concatenates the entire HTML generated from my php without changing the content on the actual page. In addition this echo, for some reason is generated as an alert, instead of being written to the page.
Thank you!
Norman