Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php]/[mysql]wyszukiwarka, nie działa
Lejto
post
Post #1





Grupa: Zarejestrowani
Postów: 1 385
Pomógł: 48
Dołączył: 23.05.2007

Ostrzeżenie: (0%)
-----


Mam taką tabele
  1. CREATE TABLE IF NOT EXISTS `linki_dane` (
  2. `tytul` text collate utf8_polish_ci NOT NULL,
  3. `dodal` text collate utf8_polish_ci NOT NULL,
  4. `opis` text collate utf8_polish_ci NOT NULL,
  5. `data` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  6. `okladka` text collate utf8_polish_ci NOT NULL,
  7. `rozszerzenie` text collate utf8_polish_ci NOT NULL,
  8. `id` int(11) NOT NULL AUTO_INCREMENT,
  9. `tagi` text collate utf8_polish_ci NOT NULL,
  10. `czas` int(11) NOT NULL,
  11. PRIMARY KEY (`id`)
  12. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci AUTO_INCREMENT=17 ;


chce w niej wyszukiwać rekordy po opisie i tytule

mam taki kod
  1. $words = array();
  2. if(isset($_GET['query']) && trim($_GET['query']))
  3. {
  4. function explode_items($text, $separator = "\n", $preserve = true)
  5. {
  6. $items = array();
  7. foreach(explode($separator,$text) as $value)
  8. {
  9. $tmp = trim($value);
  10. if($preserve)
  11. {
  12. $items[] = $tmp;
  13. }
  14. else
  15. {
  16. if(!empty($tmp))
  17. {
  18. $items[$tmp] = true;
  19. }
  20. }
  21. }
  22. if($preserve)
  23. {
  24. return $items;
  25. }
  26. else
  27. {
  28. return array_keys($items);
  29. }
  30. }
  31.  
  32. $words = explode_items($_GET['query'], ' ', false);
  33.  
  34. if(count($words))
  35. {
  36. // sformu3owanie zapytania przeszukuj?cego indeks
  37. // z uwzglednieniem wpisanych s3w i wykonanie zapytania
  38. $join = '';
  39. $where = '';
  40. $query = 'SELECT DISTINCT D.opis, D.tytul FROM linki_dane D ';
  41. foreach ($words as $index => $word)
  42. {
  43. $join .= sprintf(
  44. 'JOIN linki_dane I%d ON D.tytul = I%d.tytul',
  45. $index, $index, $index, $index, $index);
  46.  
  47. $where .= sprintf('T%d.tytul = "%s" AND ', $index, strtolower($word));
  48. }
  49. $query .= $join . 'WHERE ' . $where;
  50. // usuniecie czterech ostatnich znakw - s3owa ' AND'
  51. $query = substr($query, 0, strlen($query) - 4);
  52. $result = $db->query($query);
  53.  
  54. // wy?wietlenie wynikw
  55. echo '<hr/>';
  56. $num_rows = $result->num_rows;
  57. echo '<p>Wynik wyszukiwania s3w <b>' . htmlspecialchars(join(' ', $words)) .
  58. '</b> zawiera ' . $num_rows . ' dokument' .
  59. (($num_rows == 1) ? '' : (($num_rows < 4) ? 'y' : 'w')) . ':</p>';
  60.  
  61. // wy?wietlenie sugrowanego zapytania, je?eli stwierdzono b3edy literowe
  62.  
  63.  
  64. echo '<ul>';
  65. while ($row = $result->fetch_array())
  66. {
  67. echo '<li><b><a href="' .
  68. htmlspecialchars($row['opis']) . '">' .
  69. htmlspecialchars($row['tytul']) . '</a></b>- ' .
  70.  
  71. }
  72. echo '</ul>';
  73. }
  74. }

ale nie działa poprawie, nie wyświetla nic, jakiś błąd nie wiem gdzie


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 13:47