我有一个搜索代码,它使用分页来显示结果,但分页没有显示或正在运行。我希望每页视图显示7个结果,但似乎无法使其工作。
请帮助我指出问题,我需要了解为什么即使搜索查询是分页,分页也不起作用。
以下是我的代码:
if (isset($_GET["mainSearch"]))
{
$condition = '';
$mainSearch = SQLite3::escapeString($_GET['mainSearch']);
$searchquery = $_GET['mainSearch'];
$query = explode(" ", $searchquery);
$perpageview = 7; // amount of results to display per page
if ($_GET["pageno"])
{
$page = $_GET["pageno"];
}
else
{
$page = 1;
}
$frompage = $page*$perpageview-$perpageview;
$csql = "SELECT COUNT(*) FROM questions WHERE question LIKE '%$searchquery%' OR answer LIKE '%$searchquery%'";
$cret = $db->querySingle($csql);
$pagecount = ceil($cret/$perpageview);
if ($cret == 0)
{
echo "<div class='sug'>Did you mean to ask any of this?</div>";
$sortFullMatch = "(CASE WHEN question LIKE '%".SQLite3::escapeString($searchquery)."%' OR answer LIKE '%".SQLite3::escapeString($searchquery)."%' THEN 1 ELSE 0 END) as fullmatch";
foreach ($query as $word)
{
$x++;
if ($x == 1)
{
$condition .= "question LIKE '%$word%'";
}
else
{
$condition .= "OR question LIKE '%$word%'";
}
}
$order = " ORDER BY fullmatch DESC, quiz_id DESC ";
$condition_q = "SELECT *,". $sortFullMatch ." FROM questions WHERE ".$condition.' '.$order.' LIMIT '.$frompage.','.$perpageview;
$result = $db->query($condition_q);
$concount = "SELECT COUNT(*) as count FROM questions WHERE " . $condition;
$resultCount = $db->querySingle($concount);
$pagecount = ceil($resultCount/$perpageview);
if ($resultCount > 0)
{
if ($result)
{
while ($row = $result->fetchArray(SQLITE3_ASSOC))
{
foreach($query as $text)
{
$wording = str_replace($text, "<span style='font-weight: bold; color: #1a0dab;'>".$text."</span>", $row['answer']);
}
echo '<div class="quesbox_3">
<div class="questitle">
<h2>'.$row["question"].'</h2>
</div>
<div class="quesanswer">'.$wording.'</div>
</div>';
}
echo '<div class="modulelinks">
<div class="mfound">Founded: <span>'.$founded.'</span></div>
<div class="mowned">Ownd By: <span>'.$owner.'</span></div>
</div>
</div>';
// <div class="mavailable">Available for Export Loan: <span>'.$available.'</span></div>
}
echo '<div class="page_num">';
for ($i=1; $i <= $pageount; $i++)
{
echo '<a href="searchresult.php?mainSearch='.$mainSearch.'&pageno='.$i.'">'.$i.'</a>';
}
echo '</div>';
}
}
}
else
{
$sql = $db->prepare("SELECT * FROM questions WHERE question LIKE '%$searchquery%' or answer LIKE '%$searchquery%' LIMIT '$frompage','$perpageview'");
$bsql = $db->prepare("SELECT * FROM banks WHERE bname LIKE '%$searchquery%' or bankbrief LIKE '%$searchquery%' LIMIT 1");
$sqlcount = "SELECT COUNT(*) as count FROM questions WHERE question LIKE '%$searchquery%' OR answer LIKE '%$searchquery%'";
$retCount = $db->querySingle($sqlcount);
$pagecount = ceil($retCount/$perpageview);
$ret = $sql->execute();
$bret = $bsql->execute();
while ($row = $ret->fetchArray(SQLITE3_ASSOC))
{
$wording = str_replace($searchquery, "<span style='font-weight: bold; color: #1a0dab;'>".$searchquery."</span>", $row['answer']);
echo '<div class="quesbox_3">
<div class="questitle">
<h2>'.$row["question"].'</h2>
</div>
<div class="quesanswer">'.$wording.'</div>
</div>';
}
?>
//for page links
<div class="page_num">
<?php
for ($i=1; $i <= $pagecount; $i++)
{
echo '<a href="searchresult.php?mainSearch='.$mainSearch.'&pageno='.$i.'">'.$i.'</a>';
}
?>
</div>
<?php
}
?>
这可能是什么问题?感谢。