Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Podział na strony + Wyszukiwarka
Forum PHP.pl > Forum > PHP
seba199696
Cześć mam problem z podziałem na strony... wyszukiwarka działa dobrze lecz nie podział Daję kod:

index. php

  1. <?php
  2. include 'func.inc.php';
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>Search</title>
  9. </head>
  10.  
  11. <body>
  12. <h2> Search </h2>
  13.  
  14. <form action='' method="post">
  15. <p>
  16. <input type="text" name="keywords"/> <input type="submit" value="Search"/>
  17. </p>
  18. </form>
  19.  
  20. <?php
  21. if (isset($_POST["keywords"]))
  22. {
  23. $keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords'])));
  24. $suffix = "";
  25.  
  26. $errors = array();
  27.  
  28. if (empty($keywords)){
  29. $errors[] = '<p><em> - Please enter a search term</em></p>';
  30. } else if (strlen($keywords)<3){
  31. $errors[] = '<p><em> - Your search term must be three or more characters</em></p>';
  32. } else if (search_results($keywords) === false){
  33. $errors[] = '<p><em> - Your search returned no results</em></p>';
  34. }
  35.  
  36. if (empty($errors))
  37. {
  38. $results = search_results($keywords);
  39. $results_num = count($results) - 1;
  40. $suffix = ($result_num != 1) ? 's' : '';
  41. echo '<p>Your search for <strong>', $keywords, '</strong> returned <strong>', $results_num, ' </strong> result', $suffix,'</p>';
  42. foreach($results as $result)
  43. {
  44. echo '<p><strong><a href="',$result['url'],'">', $result['title'], '</a></strong><br>', $result['description'], '... <br>', $result['url'],'... <br>';
  45. }
  46.  
  47. if($results['pages'] >= 1)
  48. {
  49. for ($x = 1; $x<=$results['pages']; $x++)
  50. {echo '<a href="?page='.$x.'">'.$x.'</a>';}
  51. }
  52. else
  53. {
  54. foreach($errors as $error)
  55. {echo $error, '</br>';}
  56. }
  57. }
  58. }
  59.  
  60. ?>
  61. </body>
  62. </html>


func.inc.php

  1. <?php
  2. include 'db.php'; // connect
  3. function search_results($keywords){
  4. //code in here...
  5.  
  6. $returned_results = array();
  7. $where = "";
  8.  
  9. $keywords = preg_split("/[\s]+/", $keywords);
  10. $total_keywords = count($keywords);
  11.  
  12. foreach($keywords as $key=>$keyword){
  13. $where .= "`keywords` LIKE '%$keyword%'";
  14.  
  15. if($key != ($total_keywords - 1)){
  16. $where .= " AND ";
  17. }
  18. }
  19.  
  20. $per_page = 2;
  21. $page = (isset($_GET['page'])) ? (int)$_GET['page']: 1;
  22. $start = ($page -1) * $per_page;
  23.  
  24.  
  25. $results = "SELECT `title`, LEFT(`description`, 70) as `description`, `url` FROM `articles` WHERE $where LIMIT $start, $per_page";
  26.  
  27. $results_num = ($results = mysql_query($results) or die(mysql_error())) ? mysql_num_rows($results): 0;
  28.  
  29. if ($results_num === 0) {
  30. return false;
  31. }
  32. else
  33. {
  34. $pages_query = mysql_query("SELECT COUNT(`article_id`) FROM `articles`");
  35. $pages = ceil(mysql_result($pages_query, 0) / $per_page);
  36.  
  37. while ($results_row = mysql_fetch_assoc($results))
  38. { $returned_results[] = $results_row; }
  39. $returned_results['pages'] = $pages;
  40. return $returned_results;
  41. }
  42. }
  43.  
  44.  
  45. ?>
  46.  


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 smile.gif?
kadlub
a nie masz tam przypadkiem literówki $result_num
może powinno być $results_num
seba199696
Fakt smile.gif Błąd zniknął lecz stronicowanie dalej nie działa sad.gif

Odświeżam...
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.