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 { $suffix = ""; $errors[] = '<p><em> - Please enter a search term</em></p>'; $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); $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++) } else { foreach($errors as $error) } } } ?> </body> </html>
func.inc.php
<?php include 'db.php'; // connect function search_results($keywords){ //code in here... $where = ""; foreach($keywords as $key=>$keyword){ $where .= "`keywords` LIKE '%$keyword%'"; if($key != ($total_keywords - 1)){ $where .= " AND "; } } $per_page = 2; $start = ($page -1) * $per_page; $results = "SELECT `title`, LEFT(`description`, 70) as `description`, `url` FROM `articles` WHERE $where LIMIT $start, $per_page"; $results_num = ($results = mysql_query($results) or die(mysql_error())) ? mysql_num_rows($results): 0; if ($results_num === 0) { return false; } else { { $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
