Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Wyszukiwarka - Nie chce działać
Forum PHP.pl > Forum > Gotowe rozwiązania
XhtmlProject
Witam zdownloadowałem sobie ostatnio skrypt "Wyszukiwarki" Miał być prosty skrypt któremu wystarczy podać odpowiednie tabele, gdzie wyszukiwarka ma przeszukiwać informacje i szuka exclamation.gif - Kurcze nie wiem dlaczego podaje mu np:

table = "url_titles"
row = "title"

Po wpisaniu tytułu piosenki, zamiast wyszukać jedną pozycję, zwraca wszystko co znajduje się w row = "title".. U autora na stronie wszystko działa, podam linka:

Search Script

O to mój kod w którym na 100% mam coś nie tak skonfigurowane, gdyby mógł ktoś z was pomóc ...

  1. <?php
  2. include ('naglowek.htm'); // Dolaczenie naglowka HTML.
  3. ?>
  4. <head>
  5. <link rel="stylesheet" type="text/css" href="includes\css.css">
  6. </head>
  7. <html> 
  8.  <body>
  9. <font face="tahoma" size="4"> <font face="Verdana, Arial, Helvetica, sans-serif">Mysql 
  10. Search</font></font> 
  11. <form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
  12. <font face="Verdana, Arial, Helvetica, sans-serif"> Specific Word or Phrase 
  13. <input type="text" name="words" value="<?php echo($words); ?>">
  14. <br>
  15. <br>
  16. <input type="hidden" name="good" value="yes">
  17. <input type="submit" value="Search">
  18. </font>
  19. </form>
  20. <p><font face="Verdana, Arial, Helvetica, sans-serif"><br>
  21. <br>
  22. <? 
  23. /*
  24. This script is set up specifically for me so some things will need changing.
  25. I made this script because there is a lack of good mysql serching scripts out th
    ere.
  26. */
  27. if($_POST['good']=='yes') 
  28. { 
  29.  echo("<font face=\"tahoma\" size=\"3\" color=\"green\"><b>Results for $words</b></font><br><br>"); 
  30.  $location = "***"; // database host (localhost)
  31.  $username = "***"; // mysql username
  32.  $password = "***"; //mysql password
  33.  $database = "****"; //mysql database name
  34.  $db_table = "url_titles"; // mysql table name to search
  35.  $mysql_row = "title"; // This is the row in your mysql database that you want to search for text in.
  36.  
  37.  $conn = mysql_connect("$location","$username","$password"); 
  38.  if (!$conn) die ("Could not connect MySQL"); 
  39.  mysql_select_db($database,$conn) or die ("Could not open database"); 
  40.  
  41.  $query = "ALTER TABLE $db_table ORDER BY id DESC"; 
  42.  $result = mysql_query($query); // bad coding yes ;)
  43.  
  44.  $query = "SELECT * FROM $db_table"; 
  45.  $result = mysql_query($query); 
  46.  $numrows = mysql_num_rows($result); 
  47.  while($row = mysql_fetch_array($result)){ 
  48.  
  49.  if(preg_match("/$words/i", $row[$mysql_row]))
  50.  { 
  51.  
  52. /*
  53. event_id
  54. event_date
  55. event_venue
  56. event_headline
  57. event_town
  58. are all rows in my mysql table. You must replace them with your own rows / rows
  59. */
  60.  
  61. $name = ($row[title]);
  62. $rawid = ($row[event_id]); 
  63. $rawmonth = ($row[event_date]); //yes strange variable names. It works so it doesnt matter.
  64. $rawdate = ($row[event_venue]); //T just grab extra data to be added with the search tool
  65. $rawyear = ($row[event_headline]); 
  66. $newnews = preg_replace("/$words/i", "<b><font color=\"red\">$words</font></b>", $row[$mysql_row]); 
  67. $display = '<font face="tahoma" size="2"><b>' .$rawmonth . ' ' . $name. ' ' . $rawdate . ', ' . $rawyear . '</b><br>' . $newnews . '</font><br><br>'; 
  68. echo($display); 
  69. $foundcount++; 
  70.  } 
  71.  $totalcount++; 
  72.  } 
  73. if(is_null($foundcount)){$foundcount=0;} 
  74. echo("<font face=\"tahoma\" size=\"3\" color=\"green\"><b>Found $foundcount entries out of $totalcount</b></font>"); 
  75. } 
  76. ?>
  77. <br>
  78. A mysql searching tool made by <a href="http://www.gmtt.co.uk">gmtt.co.uk</a></font></p>
  79. <p>&nbsp;</p>
  80. <p><font face="Verdana, Arial, Helvetica, sans-serif"> the rows (event_date, event_venue 
  81. etc etc) are used for<br>
  82. displaying extra information about the search result.</font></p>
  83. <?php
  84. include ('stopka.htm'); // Dolaczenie stopki HTML.
  85. ?>
nospor
rety, deja vu smile.gif
Juz to wczoraj widzialem :
http://forum.php.pl/index.php?showtopic=45848

smile.gif
XhtmlProject
Niestety w dalszym ciągu nie mogę sobie poradzić z tematem, gdyby był ktoś uprzejmy pozmieniać i wkleić skrypt taki jak być powinien..
fusilis
Wiersz 45 - $query = "SELECT * FROM $db_table";
Tym zapytaniem SQL zwraca ci wszytskie wiersze z bazy $db_table, musisz dorobic WHERE, tzn dac warunek np. $query = "SELECT * FROM $db_table WHERE title ='szukane_slowo' ";
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.