Sorry for the bad title, but I don't know how to name this. My problem is that whenever I pass a value from a select box I trigger this jquery event in order to check on the check boxes. Bassically I echo $res[]; at selecctedgr.php. Do I need to use json? and how can I do this?
Mainpage:
$("#group_name").change(function(){
var groupname = $("#group_name").val();
var selectedGroup = 'gr_name='+ groupname;
$.post("selectedgr.php", {data: selectedGroup}, function(data){
$.each(data, function(){
$("#" + this).attr("checked","checked");
});
},"json");
});
PHP (selectedgr.php):
<?php
include_once '../include/lib.php';
$gr_name=mysql_real_escape_string($_POST['gr_name']);
$sqlgr = "SELECT * FROM PRIVILLAGE WHERE MAINGR_ID=".$gr_name;
$resultgr = sql($sqlgr);
while($rowgr = mysql_fetch_array($resultgr)){
$res[] = $rowgr['ACT_ID'];
}
echo $res[];
?>
$gr_nameusingmysql_real_escape_string()if it's a string (then you need to add quotes) or if it's a numeric id, check whether it's a number usingintval().$sqlgr = "SELECT * FROM PRIVILLAGE WHERE MAINGR_ID=".$gr_name;here. You should use sql placeholders (bind vars). Something like this: $sql = "SELECT * FROM PRIVILLAGE WHERE MAINGR_ID=:n"; $stmt = $pdo->prepare($sql); // bind php variables to the placeholders in the statement $stmt->bindParam(':n', $gr_name); $stmt->execute(); //sorry, i'm not a php guru ;) But you've got an idea...