Cześć mam problem z podziałem na strony... wyszukiwarka działa dobrze lecz nie podział Daję kod:
index. php
<?php
include 'func.inc.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
</head>
<body>
<h2> Search </h2>
<form action='' method="post">
<p>
<input type="text" name="keywords"/> <input type="submit" value="Search"/>
</p>
</form>
<?php
if (isset($_POST["keywords"])) {
$suffix = "";
$errors[] = '<p><em> - Please enter a search term</em></p>';
} else if (strlen($keywords)<3
){ $errors[] = '<p><em> - Your search term must be three or more characters</em></p>';
} else if (search_results($keywords) === false){
$errors[] = '<p><em> - Your search returned no results</em></p>';
}
{
$results = search_results($keywords);
$results_num = count($results) - 1; $suffix = ($result_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'],'... <br>'; }
if($results['pages'] >= 1)
{
for ($x = 1; $x<=$results['pages']; $x++)
{echo '<a href="?page='.$x.'">'.$x.'</a>';} }
else
{
foreach($errors as $error)
}
}
}
?>
</body>
</html>
func.inc.php
<?php
include 'db.php'; // connect
function search_results($keywords){
//code in here...
$returned_results = array(); $where = "";
$total_keywords = count($keywords);
foreach($keywords as $key=>$keyword){
$where .= "`keywords` LIKE '%$keyword%'";
if($key != ($total_keywords - 1)){
$where .= " AND ";
}
}
$per_page = 2;
$page = (isset($_GET['page'])) ?
(int
)$_GET['page']: 1; $start = ($page -1) * $per_page;
$results = "SELECT `title`, LEFT(`description`, 70) as `description`, `url` FROM `articles` WHERE $where LIMIT $start, $per_page";
if ($results_num === 0) {
return false;
}
else
{
$pages_query = mysql_query("SELECT COUNT(`article_id`) FROM `articles`");
{ $returned_results[] = $results_row; }
$returned_results['pages'] = $pages;
return $returned_results;
}
}
?>
Błąd mam taki: Notice: Undefined variable: result_num in C:\xampp\htdocs\search\index.php on line 40
Wie ktoś może co jest nie tak

?