Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Problem z if ($total_items < 1) {}, total_items jest mniejsze od 1 a mimo to instrukcje nie są wykonywane
Greg23
post
Post #1





Grupa: Zarejestrowani
Postów: 120
Pomógł: 0
Dołączył: 6.04.2012

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


Mam skrypt ustalający ilość wyników wyszukiwania w zależności od ilości słów w wyszukiwanej frazie:

  1. <?
  2.  
  3. if (empty($_GET['co'])) {
  4. header("Location: index.html");
  5. } else {
  6.  
  7.  
  8. function filtruj($arg) {
  9. $arg = strip_tags($arg);
  10. $arg = htmlspecialchars($arg);
  11. return $arg;
  12. }
  13.  
  14. $szukane = $_GET['co'];
  15. $szukane = iconv('utf-8', 'iso-8859-2', $szukane);
  16. $szukane_query = str_replace("+", " ", $szukane);
  17. $total_items = 0;
  18. $kind = 0;
  19.  
  20. if ($total_items < 3) {
  21.  
  22. $str=str_word_count($szukane, 0, 'ąęłóżźśćńöĄĘŁÓŻŹŚĆŃ1234567890');
  23. $minimalna_zgodnosc = $str;
  24. $sql = "SELECT id FROM (..)";
  25. $result = mysql_query($sql);
  26.  
  27. if (!$result) {
  28. die('Błąd połączenia z bazą danych');
  29. }
  30.  
  31. $total_items = (int)mysql_numrows($result);
  32.  
  33. $kind = 1;
  34. }
  35.  
  36.  
  37. if ($total_items < 1) {
  38. header("Location: ../find2-" . $kind . "-" . $szukane . "-" . $total_items . "-1/");
  39. }
  40.  
  41.  
  42.  
  43. header("Location: ../find-" . $kind . "-" . $szukane . "-" . $total_items . "-1/");
  44. }
  45. ?>



W przypadku gdy:
$total_items = (int)mysql_numrows($result) jest równa 0 powinna wykonać się ta część:

  1. if ($total_items < 1) {
  2. header("Location: ../find2-" . $kind . "-" . $szukane . "-" . $total_items . "-1/");
  3. }


Jednak nigdy ta część się nie wykonuje (gdy total_items=0)
i zawsze przekierowuje mnie na ostatni header.
O co chodzi ?


--------------------
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: 20.08.2025 - 17:32