Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> prosta wyszukiwarka
dekoder
post 1.06.2007, 08:39:07
Post #1





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 28.05.2007

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


Cześć jestem Franek biggrin.gif

Wyszukiwarka miałaby szukać po tabeli i określonym polu fraze wybrana z listy select



cuś napisałem:

  1. <form action="search.php" method="post">
  2. <select name="impreza"><option value="impreza1">impreza 1</option><option value="impreza2">impreza 2</option></select><BR />
  3. <select name="miejsce"><option value="dyskoteka">dyskoteka</option><option value="pub">pub</option></select><BR />
  4. <select name="termin"><option value="06_07">VI 07</option><option value="07_07">VII 07</option></select><BR />
  5. <input type="submit" value="szukaj">
  6. </form>
  7.  
  8. <? if (!$impreza || !$miejsce || !$termin)
  9. {
  10. print "Wypelnij wszystkie pola";
  11. }
  12.  
  13. @ $db = mysql_pconnect("host", "user", "haslo");
  14. if (!$db)
  15. {
  16. print "blad w polaczeniu";
  17. }
  18.  
  19.  
  20. $query = " select * from jakastabela ".$impreza." and ".$miejsce." and ".$termin.";
  21. $result = mysql_query($query);
  22. $num_results = mysql_num_rows($result);
  23.  
  24. print "<p>Ilosc znalezionych fraz : " .$num_results."</p>";
  25. for ($i=0; $i <$num_results; $i++) {
  26. $row = mysql_fetch_array($result);
  27. print ($i+1).". ";
  28. print stripslashes($row["header"]);
  29. print ", naglowek: ";
  30. print stripslashes($row["header2"]);
  31. print " tresc ,data:";
  32. print stripslashes($row["termin"]);
  33. print "<BR />";
  34. }
  35. ?>


wyskakuje Parse error: parse error, unexpected '\"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /www/search.php on line 27

helpy

Ten post edytował dekoder 1.06.2007, 08:45:41
Go to the top of the page
+Quote Post
Tibod
post 1.06.2007, 08:41:31
Post #2





Grupa: Zarejestrowani
Postów: 108
Pomógł: 2
Dołączył: 9.05.2007
Skąd: INTERNET

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


Masz błąd przy
  1. <?php
  2. $result - mysql_query($query);
  3. ?>

powinno być
  1. <?php
  2. $result = mysql_query($query);
  3. ?>


--------------------
"There are only 10 types of people in the world: Those who understand binary, and those who don't"
Go to the top of the page
+Quote Post
dekoder
post 1.06.2007, 08:44:38
Post #3





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 28.05.2007

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


już poprawiłem błąd : Parse error: parse error, unexpected '\"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /www/search.php on line 28
Go to the top of the page
+Quote Post
Tibod
post 1.06.2007, 08:48:46
Post #4





Grupa: Zarejestrowani
Postów: 108
Pomógł: 2
Dołączył: 9.05.2007
Skąd: INTERNET

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


Kolejny błąd masz tu:

  1. <?php
  2. $query = " select * from jakastabela ".$impreza." and ".$miejsce." and ".$termin.";
  3. ?>


powinno być

  1. <?php
  2. $query = " select * from jakastabela ".$impreza." and ".$miejsce." and ".$termin;
  3. ?>

bez ostatnich dwóch znaków.


--------------------
"There are only 10 types of people in the world: Those who understand binary, and those who don't"
Go to the top of the page
+Quote Post
dekoder
post 1.06.2007, 08:54:07
Post #5





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 28.05.2007

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


kolejny.....

  1. <?php
  2. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/search.php on line 22
  3. ?>
Go to the top of the page
+Quote Post
Tibod
post 1.06.2007, 09:09:18
Post #6





Grupa: Zarejestrowani
Postów: 108
Pomógł: 2
Dołączył: 9.05.2007
Skąd: INTERNET

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


Bo Twój SELECT też jest do niczego:

  1. <?php
  2. $query = 'select * from jakastabela WHERE impreza="'.$impreza.'" and miejsce='".$miejsce."' and termin='".$termin'"';
  3. ?>


W selekcie musisz mieć WHERE abo móc coś wyszukać i muszisz podać jakiej wartości w któej kolumnie wyszukujesz.


--------------------
"There are only 10 types of people in the world: Those who understand binary, and those who don't"
Go to the top of the page
+Quote Post
dekoder
post 1.06.2007, 09:22:14
Post #7





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 28.05.2007

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


no nie ..

  1. <?php
  2. Parse error: parse error, unexpected '"' in /www/search.php on line 20
  3. ?>


tam nie ma żadnego slasha...
Go to the top of the page
+Quote Post
Tibod
post 1.06.2007, 09:32:48
Post #8





Grupa: Zarejestrowani
Postów: 108
Pomógł: 2
Dołączył: 9.05.2007
Skąd: INTERNET

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


Sory teraz mój błąd. W ostatniej części zabrakło kropki

  1. <?php
  2. $query = 'select * from jakastabela WHERE impreza="'.$impreza.'" and miejsce="'.$miejsce.'" and termin="'.$termin.'"';
  3. ?>


Ten post edytował Tibod 1.06.2007, 11:18:50


--------------------
"There are only 10 types of people in the world: Those who understand binary, and those who don't"
Go to the top of the page
+Quote Post
dekoder
post 1.06.2007, 10:06:41
Post #9





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 28.05.2007

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


  1. <?php
  2. $query = 'select * from tabela WHERE pole1="'.$impreza.'" and pole2='".$miejsce."' and pole3='".$termin.'"';
  3. ?>

rezultat:

Parse error: parse error, unexpected '\"' in /www/search.php on line 21" title="Zobacz w manualu PHP" target="_manual


edit:

  1. <?php
  2. $query = 'select * from tabela WHERE pole1="'.$impreza.'" and pole2="'.$miejsce.'" and pole3="'.$termin.'" ';
  3. ?>


OTO POPRAWNE ZAPYTANIE smile.gif dzięki miszczu

Ten post edytował dekoder 1.06.2007, 10:15:07
Go to the top of the page
+Quote Post
nospor
post 1.06.2007, 10:16:35
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




@dekoder z kazdym bledem przedmowcy bedziesz lecial na forum? Poczytaj troche manuala a nie z byle bykiem walisz posty. Troche samodzielnosci.

Kod
$query = 'select * from tabela WHERE pole1="'.$impreza.'" and pole2="'.$miejsce.'" and pole3="'.$termin.'"';
Tak jest poprawnie w php. Czy to jest poprawne zapytanie to juz nie wnikam.

@dekoder przeczytaj bardzo dokładnie:
http://pl.php.net/manual/pl/language.types.string.php
http://pl.php.net/manual/pl/language.operators.string.php

edit: no widze ze sam poprawiles. Co nie zmienia faktu ze najpierw pomysl - potem lec na forum. No i lektura co ci dalem nadal jest obowiazkowa smile.gif


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
dekoder
post 1.06.2007, 11:57:46
Post #11





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 28.05.2007

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


Coraz bardziej zaczynam kochać manuale.

W nich jest wszystko a sztuka go przeczytać i zrozumieć.

Hola, za pare godzin przypisze tu jakieś modyfikacje aarambo.gif
Go to the top of the page
+Quote Post
colinQ
post 1.06.2007, 14:46:47
Post #12





Grupa: Zarejestrowani
Postów: 340
Pomógł: 2
Dołączył: 25.12.2006

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


Mistrzu, pierwsze co kopie po oczach, to zmienne których nie ma dry.gif
  1. <?php
  2. !$impreza || !$miejsce || !$termin
  3. ?>


Nie ma takich zmiennych jak $impreza czy $miejsce.

Najpierw wczytaj $_POST['impreza'] do $impreza itp.

A jeżeli nie masz możliwości wczytania wcześniejszego bo wykorzystujesz je do "zabezpieczenia" to zrób poprostu:
  1. <?php
  2. if (!$_POST['impreza'] || !!$_POST['miejsce'] || !!$_POST['termin'])
  3. ?>


A pozniej możesz sobie ułatwić i przypisać do ziennych $impreza zmienne $_POST cool.gif :
  1. <?php
  2. $impreza = $_POST['impreza'];
  3. ?>


--------------------
-> Kanał YouTube: http://www.youtube.com/user/screencup
-> Screencup - podcast/screencast, recenzja Makowych aplikacji
-> www.screencup.pl - witryna internetowa podcastu
Go to the top of the page
+Quote Post
dekoder
post 3.06.2007, 13:33:22
Post #13





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 28.05.2007

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


Witam.
Dzięki za odzew.

skasowałem bo troche niewyraźnie było napisane:
chodzi o to że szukana fraza ma zawierać polskie znaki - więc w value nie będę mógł umieścić tego słowa.
Więc chciałbym je podmienić już w skrypcie wyszukiwarki na to odpowiednie.

  1. <form action="search.php" method="post">
  2. <select name="impreza"><option value="impreza1">impreza 1</option><option value="impreza2">impreza 2</option></select><BR />
  3. <select name="miejsce"><option value="dyskoteka">dyskoteka</option><option value="pub">pub</option></select><BR />
  4. <select name="termin"><option value="06_07">VI 07</option><option value="07_07">VII 07</option></select><BR />
  5. <input type="submit" value="szukaj">
  6. </form>


  1. <IF (!$_POST['impreza'] || !$_POST['miejsce'] || !$_POST['termin'])
  2.  
  3. {
  4. print "Wypelnij wszystkie pola";
  5. exit;
  6. }
  7.  
  8. $impreza = addslashes($impreza);
  9. $miejsce = addslashes($miejsce);
  10. $termin = addslashes($termin);
  11.  
  12.  
  13. @ $db = mysql_pconnect("xxx", "xxx", "xxx");
  14. IF (!$db)
  15. {
  16. print "blad w polaczeniu";
  17. exit;
  18. }
  19.  
  20. mysql_select_db("navigatort_db1");
  21.  
  22.  
  23. $query = 'select * from sys_grouptextentry WHERE header="'.$impreza.'"; and content="'.$miejsce.'" and header2="'.$termin.'" ';
  24. $result = mysql_query($query);
  25. $num_results = mysql_num_rows($result);
  26.  
  27. print " .$num_results. ";
  28. FOR ($i=0; $i <$num_results; $i++) {
  29. $row = mysql_fetch_array($result);
  30. print ($i+1).". ";
  31. print stripslashes($row["header"]);
  32. print ", naglowek: ";
  33. print stripslashes($row["header2"]);
  34. print " tresc ,data:";
  35. print stripslashes($row["date"]);
  36. print "<BR />";
  37. }
  38. ?>


coś nie działa ...
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/search.php on line 25

Ten post edytował dekoder 3.06.2007, 14:05:16
Go to the top of the page
+Quote Post
nospor
post 3.06.2007, 16:28:49
Post #14





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




  1. <?php
  2. //....
  3. $result = mysql_query($query) or die('zapytanie: '.$query.'----blad: '.mysql_error());
  4. //....
  5. ?>


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
dekoder
post 3.06.2007, 20:06:28
Post #15





Grupa: Zarejestrowani
Postów: 22
Pomógł: 0
Dołączył: 28.05.2007

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


źle .

<form action="search.php" method="post">
<select name="impreza">
<option value="rajd">rajd samochodowy-dział1</option>
<option value="impreza2">impreza 2</option></select><BR />
<input type="submit" value="szukaj">
</form>


tibod,nospor lub ktoś inny:

musi szukać w KOLUMNIE po id artykułu, id są niestety stałe

np. w kolumnie article_id są różne pola o innych id a chciałbym wybrać tylko te, które wskazał użytkownik w formularzu - a żeby widok rajd samochodowy w formularzu się nie zmienił.
czy ukryta opcja tu pomoże? jak jej używać

pierwszy select wybiera id, ale w nazwie nie pokazuje ID tylko rajd samochodowy
drugi select to już szukane , zadeklarowane słowo

problem jest również z wyświetlaniem, bo wyświetla wszystkie wyniki...


dużo pisania, mało roboty..

  1. <? IF (!$_POST['impreza'] || !$_POST['miejsce'] || !$_POST['termin'])
  2.  
  3. {
  4. print "Wypelnij wszystkie pola";
  5. exit;
  6. }
  7.  
  8. @ $db = mysql_pconnect("xxx", "xxx", "xxx");
  9. IF (!$db)
  10. {
  11. print "blad w polaczeniu";
  12. exit;
  13. }
  14.  
  15. mysql_select_db("navigatort_db1");
  16.  
  17.  
  18. $query = 'select * from sys_grouptextentry WHERE header=" '.$impreza.' " like " ' .$impreza. '" ';
  19. $result = mysql_query($query) OR die('zapytanie: '.$query.'----blad: '.mysql_error());
  20. $num_results = mysql_num_rows($result);
  21.  
  22. print "Ilosc wynikow : $num_results ";
  23. FOR ($i=0; $i <$num_results; $i++) {
  24. $row = mysql_fetch_array($result);
  25. print ($i+1).". ";
  26. echo "<table border='0' width='555' id='oferta'>";
  27. echo "<tr>";
  28. echo "<td colspan='2' id='oferta'><center>";
  29. echo stripslashes($row["header"]);
  30. echo "</center></td></tr>";
  31. echo "<tr>";
  32. echo "<td width='450' id='oferta'><p>";
  33. echo stripslashes($row["content"]);
  34. echo "</p></td><td width='105' id='oferta'><center>";
  35. echo stripslashes($row["header2"]);
  36. echo "</center></td></tr>";
  37. echo "<tr>";
  38. echo "<td colspan=2 id='oferta'><center>czytaj wiecej</center></td></tr>";
  39. echo "<tr>";
  40. echo "</table>";
  41. }
  42. ?>
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 16.06.2025 - 18:37