当您按下“加载更多”按钮时,我希望将限制提高。 我已经有了正确的设置来获取一个数字,当您用AJAX按下按钮时,这个数字会一直加2。
唯一的问题是我不能将该数字放在OOP类中的查询中。 现在,echo $ count工作正常,将数字放入限制查询中一定有问题。 当我用简单的整数替换极限查询时,一切工作正常。
我希望有人能找到问题所在...
<?php
require_once '../bootstrap.php';
if (!empty($_POST['postNewCount'])) {
$post = new Post();
$count = $_POST['postNewCount'];
//settype($postNewCount, 'integer');
echo $count;
$count = $post->setPostNewCount($count);
} else {
echo 'loading';
}
class Post
{
protected $postNewCount;
public function getPostNewCount()
{
return $this->postNewCount;
}
public function setPostNewCount($postNewCount)
{
$this->postNewCount = $postNewCount;
return $this;
}
public function selectSearchAndLimit()
{
$limitPosts = $this->postNewCount;
$conn = Db::getInstance();
$innerhtml = $this->checkIfSearchIsEmpty();
$result = $conn->prepare('SELECT posts.id
as post_id, users.id
as user_id, posts.visibility, posts.message, posts.image,
posts.filter, posts.`color1`, posts.`color2`, posts.`color3`,
posts.`color4`, users.`firstname`, users.`lastname`,
users.`email`, posts.timePost
FROM posts
JOIN users on users.id = posts.usersId
WHERE posts.visibility = 1
AND posts.message
LIKE :innerhtml
ORDER BY posts.id DESC
LIMIT :limitPosts ');
$result->bindParam(':limitPosts', $limitPosts);
$result->bindValue(':innerhtml', '%'.$innerhtml.'%');
$result->execute();
return $result;
}
}