I'm trying to build an infinite scroll with search. So far I came to this problem:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DESC LIMIT 0, 4'.
Can anyone help me with this problem?
if(isset($_GET["starts"], $_GET["limits"])){
$search = htmlspecialchars($_GET['Search'],ENT_QUOTES,'utf-8');
$start = htmlspecialchars($_GET['starts'],ENT_QUOTES, 'utf-8');
$limit = htmlspecialchars($_GET['limits'],ENT_QUOTES, 'utf-8');
$stmt = $conn->prepare("SELECT `jobtitle`, `company`, `location`,
`employment`, `email`, `Description` FROM `featured job` WHERE jobtitle LIKE
`:jobtitle` DESC LIMIT :starts, :limits");
$stmt->bindParam(":starts", intval(trim($start)), PDO::PARAM_INT );
$stmt->bindParam(":limits", intval(trim($limit)), PDO::PARAM_INT );
$stmt->bindParam(":jobtitle",$search);
$stmt->execute();
foreach ($posts as $data) {
echo "<h2>".$data['jobtitle']."</h2>";
}
Here's my ajax code
$(document).ready(function(){
var limits = 4;
var starts = 0;
var action = 'inactive';
function load_job_data(limits, starts)
{
$.ajax({
url:"load_more.php",
method:"GET",
data:{limits:limits, starts:starts},
cache:false,
success:function(data)
{
$('.results').append(data);
if(data == '')
{
$('#load_data_messages').text("Your potential jobs is loading");
$('#load_data_messages').css("color", "green");
action = 'active';
}
else
{
$('#load_data_messages').text("Out of jobs! please come back later!");
$('#load_data_messages').css("color","red");
action = "inactive";
}
}
});
}
if(action == 'inactive')
{
action = 'active';
load_job_data(limits, starts);
}
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $(".load_data").height()
&& action == 'inactive')
{
action = 'active';
starts = starts + limits;
setTimeout(function(){
load_job_data(limits, starts);
}, 1000);
}
});
});