Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] petla if problem
Lonas
post
Post #1





Grupa: Zarejestrowani
Postów: 576
Pomógł: 14
Dołączył: 9.11.2005

Ostrzeżenie: (20%)
X----


Dlaczego przy takim kodzie
  1. <?php
  2. if( $dzial != NULL && $gama !==NULL ) {
  3. $sqlwhere .= " `dzial` = '$dzial'";
  4. }
  5.  
  6. if( $dzial !== NULL && $gama !=NULL ) {
  7. $sqlwhere .= "`gama` = '$gama' ";
  8.  
  9. }
  10. if( $dzial != NULL && $gama !=NULL ) {
  11. $sqlwhere .= " `dzial` = '$dzial' and `gama` = '$gama' ";
  12. }
  13.  
  14.  
  15. if($sortuj != NULL) {
  16. $sqlwhere .= " order by '$sortuj' desc";
  17. }
  18.  
  19. if($sortuj !== NULL) {
  20. $sqlwhere .= " ";
  21. }
  22. ?>


zaznaczajac naraz i game i dzial otrzymuje taki wynik

where `dzial` = '2'`gama` = 'A' `dzial` = '2' and `gama` = 'A'

Ten post edytował L.Pociask 10.03.2006, 11:42:09
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Lonas
post
Post #2





Grupa: Zarejestrowani
Postów: 576
Pomógł: 14
Dołączył: 9.11.2005

Ostrzeżenie: (20%)
X----


Ok mam (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

  1. <?php
  2. $wh = array();
  3. if (!empty($dzial))
  4.  $wh[] = 'dzial= '.$dzial;
  5. if (!empty($gama))
  6.  $wh[] = 'gama='.$gama;
  7.  
  8. if (!empty($wh))
  9.  $where = 'where '.implode(' and ', $wh);
  10. else
  11.  $where = '';
  12.  
  13. $sql = 'select * from marza_ujemna '.$where ;
  14. ?>


żeby teraz dodać sort by to musze wprowadzić. np

$sort = array () ? ?

Ten post edytował L.Pociask 10.03.2006, 12:33:03
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.09.2025 - 02:08