Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] zagnieżdzanie funcji
$liwa
post 29.07.2007, 22:47:36
Post #1





Grupa: Zarejestrowani
Postów: 63
Pomógł: 0
Dołączył: 19.07.2006

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


  1. <?php
  2. function search($sSearch, $sWord, $aFieldsB, $aOFields)
  3. {
  4. if($sSearch != '0')
  5. {
  6. searchOneCategory($sSearch, $sWord, $sWhere);
  7. echo $sWhere; //tutaj nie wyświetla
  8. }
  9. }
  10.  
  11. function searchOneCategory($sSearch, $sWord, $sWhere)
  12. {
  13. $sWhere = "$sSearch like '%$sWord%'";
  14. echo $sWhere; //tutaj wyświetla
  15. return $sWhere;
  16. }
  17. ?>

Problem tkwi w tym, że nie zwraca mi warości $sWhere z funkcji searchOneCategory, musiałem jakiś błąd popełnić, ale w manualu nie znalazłem pomocy, przynajmniej nie zauważyłem.

Ten post edytował $liwa 29.07.2007, 22:48:11
Go to the top of the page
+Quote Post
nexis
post 29.07.2007, 23:00:22
Post #2





Grupa: Zarejestrowani
Postów: 1 012
Pomógł: 109
Dołączył: 26.09.2003
Skąd: nexis.pl

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


Możesz mi wyjaśnić czemu w funkcji searchOneCategory przekazujesz parametr $sWhere, a następnie go i tak wewnątrz funkcji nadpisujesz? A po drugie zdecyduj się: albo echo albo return, bo razem to nie bardzo.


--------------------
Zend Certified Engineer

Kliknij POMÓGŁ jeśli moja odpowiedź okazała się użyteczna!
Go to the top of the page
+Quote Post
kosmowariat
post 29.07.2007, 23:01:38
Post #3





Grupa: Zarejestrowani
Postów: 235
Pomógł: 17
Dołączył: 18.07.2007
Skąd: Białystok

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


bo return zwraca wartość. nie wykonuje przy tym żadnego przypisania...

  1. <?php
  2. function search($sSearch, $sWord, $aFieldsB, $aOFields)
  3. {
  4. if($sSearch != '0')
  5. {
  6. $result = searchOneCategory($sSearch, $sWord, $sWhere);
  7. echo $result; //tutaj nie wyświetla
  8. }
  9. }
  10.  
  11. function searchOneCategory($sSearch, $sWord, $sWhere)
  12. {
  13. $sWhere = "$sSearch like '%$sWord%'";
  14. echo $sWhere; //tutaj wyświetla
  15. return $sWhere;
  16. }
  17. ?>


poza tym widzę że i tak nie ma odpowiednich zmiennych w funkcji search ale to już inna kwesta...
Go to the top of the page
+Quote Post
kossa
post 29.07.2007, 23:03:14
Post #4





Grupa: Zarejestrowani
Postów: 1 165
Pomógł: 9
Dołączył: 9.04.2002
Skąd: Toruń

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


  1. <?php
  2. function search($sSearch, $sWord, $aFieldsB, $aOFields)
  3. {
  4. if($sSearch != '0')
  5. {
  6. $ret = searchOneCategory($sSearch, $sWord, $sWhere); 
  7. }
  8.  
  9.  return $ret;
  10. }
  11.  
  12. function searchOneCategory($sSearch, $sWord, $sWhere)
  13. {
  14. $sWhere = "$sSearch like '%$sWord%'";
  15. return $sWhere;
  16. }
  17.  
  18.  
  19. //wywolanie f-cji
  20.  
  21. echo search($sSearch, $sWord, $aFieldsB, $aOFields);
  22. ?>


--------------------
Go to the top of the page
+Quote Post
$liwa
post 29.07.2007, 23:06:12
Post #5





Grupa: Zarejestrowani
Postów: 63
Pomógł: 0
Dołączył: 19.07.2006

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


Racja dzięki, zapomniałem.
@kosmowariat bo to jest wycinek funkcji
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: 25.04.2024 - 06:12