$data_sql = "SELECT * FROM teachers_table LIMIT {$limit} OFFSET {$offset}";
Returns the following error:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit OFFSET offset' at line 1
I have earlier created two variables in ajax:
$.ajax({
type: "GET",
url: "mini_profiles.php",
data: {
'offset':0,
'limit':9
},
success:function(data){
$('body').append(data);
flag += 9;
}
and then I assign then to string values which I tried to call in the SQL code:
$limit = 'limit';
$offset = 'offset';
Does what I've done to create the variables and assign them into the statement seem accurate? I realise I'm getting an error so there's obviously an issue somewhere, but just not sure what part of my code is causing the problem.
Many thanks for reading this.
Update to the original post to include complete ajax function:
<script type="text/javascript">
<!--make the ajax call when page loads-->
$(document).ready(function()
{
var flag = 0;
<!--pass the two parameters, offset and limit-->
$.ajax({
type: "GET",
url: "mini_profiles.php",
data: {
'offset':0,
'limit':9
},
success:function(data){
$('body').append(data);
flag += 9;
}
});
//Every time when we scroll we check the current value of scrollbar
//and if it has reached the bottom of the page
$(window).scroll(function(){
if($(window).scrollTop()>= $(document).height() - $(window).height()){
//this is what happens at the bottom - same ajax function but we now want to offset by+=3 everytime
//so above we create a variable and increase by three whenver the ajax call is successful
$.ajax({
type: "GET",
url: "mini_profiles.php", //this is the ajax function calling the get_data.php
data: {
'offset':flag,
'limit':9
},
success:function(data){
$('body').append(data);
flag += 9;
}
});
}
});
});
</script>