Reputation: 123
I have a live search table ajax which i send data from dropdown. The live table is working if a single data is send. But if there is two data, it wont work. Below is the example of non working ajax.
$(document).ready(function(){
load_dataa();
function load_dataa(query1='',query2='')
{
$.ajax({
url:"viewattendance.php",
method:"POST",
data:{query1:query1,query2:query2},
success:function(data)
{
$('#table2 tbody').hide().html(data);
$('#table2 tbody').hide().fadeIn( 1000);
}
})
};
$('#year').change(function(){
$('#hidden_year').val($('#year').val());
var query1 = $('#hidden_year').val();
load_dataa(query1);
});
$('#month').change(function(){
$('#hidden_month').val($('#month').val());
var query2 = $('#hidden_month').val();
load_dataa(query2);
});
});
and PHP file
if($_POST["query1"] != '' && $_POST["query2"] != '' )
{
$query1=$_POST["query1"];
$query2=$_POST["query2"];
$query = "
SELECT user.user_type,user.user_id,user.first_name,attendance_year,attendance_month,one,two FROM attendance INNER JOIN user ON user.user_id = attendance.student_id
WHERE attendance_year IN (".$query1.") AND attendance_month IN (".$query2.")
";
}
The problem is, the live table is not working when i tried to pass two data. IF i pass one data like this, it will work(working) :
$(document).ready(function(){
load_dataa();
function load_dataa(query1='')
{
$.ajax({
url:"viewattendance.php",
method:"POST",
data:{query1:query1},
success:function(data)
{
$('#table2 tbody').hide().html(data);
$('#table2 tbody').hide().fadeIn( 1000);
}
})
};
$('#year').change(function(){
$('#hidden_year').val($('#year').val());
var query1 = $('#hidden_year').val();
load_dataa(query1);
});
$('#month').change(function(){
$('#hidden_month').val($('#month').val());
var query2 = $('#hidden_month').val();
load_dataa(query2);
});
});
with single data php file(working)
if($_POST["query1"] != '' )
{
$query1=$_POST["query1"];
$query = "
SELECT user.user_type,user.user_id,user.first_name,attendance_year,attendance_month,one,two FROM attendance INNER JOIN user ON user.user_id = attendance.student_id
WHERE attendance_year IN (".$query1.")
";
}
Appreciate any form of help ty.
EDIT: solved it by editing some of the code:
$(document).ready(function(){
load_dataa();
function load_dataa(query1,query2)
{
$.ajax({
url:"viewattendance.php",
method:"POST",
data:{query1:query1,query2:query2},
success:function(data)
{
$('#table2 tbody').hide().html(data);
$('#table2 tbody').hide().fadeIn( 1000);
}
})
};
$('#year').change(function(){
$('#hidden_year').val($('#year').val());
var query1 = $('#hidden_year').val();
$('#month').change(function(){
$('#hidden_month').val($('#month').val());
var query2 = $('#hidden_month').val();
load_dataa(query1,query2);
});
});
});
Upvotes: 0
Views: 119
Reputation: 630
Check your code and fetch step by step
Upvotes: 1