Getting values of checkboxes to run a SELECT on the DB.
JS :
function passList() {
var p=[];
$('input.first').each( function() {
if($(this).prop('checked')) {
p.push($(this).attr('rel'));
}
} );
var q=[];
$('input.second').each( function() {
if($(this).prop('checked')) {
q.push($(this).attr('rel'));
}
} );
$.ajax( {
url:'delprocess.php',
type:'POST',
data: {list:p,type:q},
success: function(res) {
$("#result").html(res);
}
});
My HTML :
<body>
<input type="checkbox" class="first" rel="list1" onclick="passList()">list1<br />
<input type="checkbox" class="first" rel="list2" onclick="passList()">list2<br />
<input type="checkbox" class="first" rel="list3" onclick="passList()">list3<br />
<input type="checkbox" class="first" rel="list4" onclick="passList()">list4<br />
<br><br><br>
<input type="checkbox" class="second" rel="type1" onclick="passList()">type1<br />
<input type="checkbox" class="second" rel="type2" onclick="passList()">type2<br />
<input type="checkbox" class="second" rel="type3" onclick="passList()">type3<br />
<br><br><br>
<div id="result"> </div>
</body>
process.php :
<?php
if(isset($_POST['list']) && !isset($_POST['type'])) {
foreach ($_POST['list'] as $list) {
echo "this is $list<br />";
//mysql_query to SELECT FROM mytable WHERE list=$list
}
}
else if(!isset($_POST['list']) && isset($_POST['type'])) {
foreach ($_POST['type'] as $type) {
echo "type is : $type<br />";
//mysql_query to SELECT FROM mytable WHERE type=$type
}
}
else if(isset($_POST['list']) && isset($_POST['type'])) {
foreach ($_POST['list'] as $list ) {
echo "The list is : $list<br />";
}
foreach ($_POST['type'] as $type){
echo "the TYPE is : $type<br />";
}
//NEED HELP IN UNDERSTANDING THE QUERY TO SELECT FROM mytable WHERE (list=list&&type=$type)
}
?>
So this is what i got sofar.
I am unable to generate the query to select from the DB using the var $type and $list. I am able to echo the selected checkboxes, but unable to figureout how to construct the query.
Please help.
Subject
Written By
Posted
Getting values of checkboxes to run a SELECT on the DB.
September 22, 2013 06:31PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.