Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z logiką do pola checkbox
dominick
post 8.02.2015, 14:13:40
Post #1





Grupa: Zarejestrowani
Postów: 88
Pomógł: 0
Dołączył: 30.05.2014

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


Witam serdecznie mam problem z logiką do pola checkbox. Mianowicie mam input text "phrase" i input checkbox "where" logika wyszukiwania działa prawidłowo gdyś sprawdza dwa pola i phrase i where jednak gdy jedno z nich nie ma wartości to pojawia się błąd. Chciałbym aby w zmiennej where była domyśla wartość title a dopiero gdy kliknie się w checkbox to powinna zmienić się na title_and_description. Wszystko odbywa się poprzez GET.
aktualnie mam coś takiego i wszystko jest ok gdy checkbox jest kliknięty wtedy wartość to title_and_description jednak gdy go odklikam to jest błąd bo nie ma wartości domyślnej.
  1. public function search_phrase($phrase, $where = 'title')
  2. {
  3. $phrase = UTF8::trim($phrase);
  4.  
  5. if(UTF8::strlen($phrase) >= 4)
  6. {
  7. if($where == 'title' || $where == 'description')
  8. {
  9. $where = $this->_db->quote_column(
  10. $where == 'title' ? "annoucement_title" : "annoucement_content"
  11. );
  12. }
  13. else
  14. {
  15. $where = $this->_db->quote_column('"annoucement_title", "annoucement_content"');
  16. }
  17.  
  18. $this->where(DB::expr('MATCH('.$where.')'), "AGAINST", DB::expr("(:phrase IN BOOLEAN MODE)"))
  19. ->param(':phrase', $phrase);
  20. }
  21. else
  22. {
  23. $phrase = '%'.$phrase.'%';
  24.  
  25. if($where == 'title')
  26. {
  27. $this->where('annoucement_title', 'LIKE', $phrase);
  28. }
  29. elseif($where == 'description')
  30. {
  31. $this->where('annoucement_content', 'LIKE', $phrase);
  32. }
  33. else
  34. {
  35. $this->where_open();
  36. $this->where('annoucement_title', 'LIKE', $phrase);
  37. $this->or_where('annoucement_content', 'LIKE', $phrase);
  38. $this->where_close();
  39. }
  40.  
  41. }
  42.  
  43. return $this;
  44. }


Chodzi o to, że jeżeli checkbox nie jest checked to, żeby $where miało wartość title

może zrobić to na radio i jedną opcje zrobić na hidden?
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 Wersja Lo-Fi Aktualny czas: 18.07.2025 - 01:40