我一直在本地主机上的博客网站上工作。我终于准备好将其移至实时服务器,但是我的许多查询都停止了工作!以下是一个有效但又无法正常工作的查询示例。有什么我想念的吗?在此先感谢:)
public function search($query, $start, $limit)
{
$stmt = $this->pdo->prepare("SELECT * FROM `articles` WHERE `status` = 1 AND LOWER(`title`) LIKE LOWER(:query) ORDER BY `id` DESC LIMIT :start, :limit");
$stmt->bindParam(":query", $query, PDO::PARAM_STR);
$stmt->bindParam(":start", $start, PDO::PARAM_INT);
$stmt->bindParam(":limit", $limit, PDO::PARAM_INT);
$stmt->execute();
$articles = $stmt->fetchAll(PDO::FETCH_OBJ);
$count = $stmt->rowCount();
if($count > 0)
{
foreach($articles as $article)
{
$date = date('F jS, Y', strtotime($article->published));
echo '<div class="article">
<h2>'.$article->title.'</h2>
<h4>'.$article->subtitle.', <span>'.$date.'</span></h4>
<div class="imageWrapper">
<img src="'.BASE_URL.$article->banner.'">
<div class="articleHover">
<p>'.$this->shorten(strip_tags($article->content), 300).'...</p>
</div>
</div>
<div id="mobileDescription"><p>'.$this->shorten(strip_tags($article->content), 300).'...</p></div>
<a href="article/'.$article->link.'">Read Article</a>
</div>';
}
}
else
{
echo "No Search Results...";
}
}
没有引发错误,只是似乎返回了0行的计数(通过回显$ count进行测试)。表中有数据,并且所有设置均正确。如果您在https://nerbgamez.ca/blog上查看页面,则可以在首页上正确看到文章。这似乎只是搜索的问题。下面,我将显示用于调用此查询的ajax函数,也许会有所帮助。
Ajax功能
index = 0;
app = 2;
...
$.ajax({
url: 'https://nerbgamez.ca/blog/inc/ajaxFunctions.php',
type: 'POST',
data: {start:index, limit:app, index:3, query:$('#query').val()},
success: function (res) {
$('#searchResults').html(res);
}
});
ajaxFunctions.php
if($index == 3)
{
$start = $_POST['start'];
$limit = $_POST['limit'];
$query = '%'.$_POST['query'].'%';
$getFromA->search($query, $start, $limit);
}