你好朋友我想知道如何在搜索引擎中添加分頁。我已經嘗試了很多次,在搜索引擎中添加分頁,但每次我都失敗了。是否有任何人誰修改我下面的代碼添加分頁:搜索引擎和分頁
的index.php
<?php include 'func.inc.php'; ?>
<html>
<head>
<title>Search</title>
</head>
<body>
<h2> Search </h2>
<form action="" method="POST">
<p>
<input type="text" autocomplete="off" name="keywords" /> <input type="submit" value="Search" />
</p>
</form>
<?php
if (isset($_POST['keywords'])) {
$suffix = "";
$keywords = mysql_real_escape_string (htmlentities (trim($_POST['keywords'])));
$errors = array();
if (empty($keywords)) {
$errors[] = 'Please enter a search term';
} else if (strlen($keywords)<3) {
$errors[] = 'Your search term must be three or more character';
} else if (search_results($keywords) === false) {
$errors[] = 'Your search for ' .$keywords. ' returned no result';
}
if (empty($errors)) {
$results = search_results ($keywords);
$results_num = count ($results);
$suffix = ($results_num !=1) ? 's' : '';
echo '<p> Your search for <strong>', $keywords,'</strong> returned <strong>',$results_num,'</strong> result',$suffix,'</p>';
foreach($results as $result) {
echo '<p><strong><a href="',$result['url'],'">', $result['title'],'</a></strong> <br>', $result['description'],'...<br>', $result['url'],'</p>';
}
} else {
foreach ($errors as $error) {
echo $error, '</br>';
}
}
}
?>
</body>
</html>
func.inc.php
<?php
include 'db.inc.php';
function search_results($keywords) {
$returned_results = array();
$where ="";
$keywords = preg_split('/[\s]+/', $keywords);
$total_keywords = count($keywords);
foreach ($keywords as $key=>$keyword) {
$where .="`keywords` LIKE '%$keyword%'";
if ($key != ($total_keywords - 1)) {
$where .= "AND";
}
}
$results = "SELECT `title`, LEFT(`description`, 70) as `description`, `url` FROM `articles` WHERE $where";
$results_num = ($results = mysql_query($results)) ? mysql_num_rows($results): 0;
if ($results_num === 0) {
return false;
} else {
while ($results_row = mysql_fetch_assoc($results)) {
$returned_results[] = array(
'title' => $results_row['title'],
'description' => $results_row['title'],
'url' => $results_row['url']
);
}
return $returned_results;
}
}
?>
,我有一個問題,使關閉本部門頂部的關閉按鈕。