filtri di query [php-mysql]

luigi777

Utente Attivo
14 Feb 2008
1.086
1
38
43
Massa, Italy
Salve, volevo sapere come fare un filtro che non ricordo più...
ho active=4 che vuol dire che il dato e nel cestino . ho active=2 vuol dire che e nascosto.
ho questo codice:
PHP:
$query = "SELECT utenti._user as _user , news_categorie.titolo as _cat , news.* FROM utenti 
       INNER JOIN news 
          ON utenti.id = news._userid INNER JOIN news_categorie 
          ON news_categorie.id = news._catid ";

if(!empty($_GET['cat'])) {
          $query.="WHERE _catid=".(int)$_GET['cat'];
          $cfg_current = $cfg_news_list_cat_admin;
}elseif(!empty($_GET['uid'])){
          $query.="WHERE news._userid=".(int)$_GET['uid'];
          $cfg_current = $cfg_news_list_utenti_admin;
}
    $pag = new Paginazione($query,$cfg_current, $pagina);

mi sembra che dovrei aggiungere un altra get e fare where active=4 per quelli che sono nel cestino e where active=2 per quelli che sono nascosti..

e cosi?
grazie mille e buone feste.
 
Ultima modifica:
ho quasi fatto l'unico inghippo e che mi da questo errore:
Parse error: syntax error, unexpected '==' (T_IS_EQUAL), expecting ')' in D:\xampp\htdocs\sito\admin\news.php on line 64

il codice e questo:
PHP:
}elseif(!empty($_GET['a']=='trash')){
          $query.="WHERE news.active=4";
          $cfg_current = 10;
}elseif(!empty($_GET['a']=='hidden')){
          $query.="WHERE news.active=2";
          $cfg_current = 10;

come mai?
grazie mille.
 
Prendendo in considerazione solo l'ultimo pezzo di codice che hai riportato, l'errore occorre dal momento che adoperi l'operatore di comparazione all'interno del costrutto empty.

Dovresti fare così invece:
PHP:
}elseif(!empty($_GET['a']) && $_GET['a']=='trash')){
          $query.="WHERE news.active=4";
          $cfg_current = 10;
}elseif(!empty($_GET['a']) && $_GET['a']=='hidden')){
          $query.="WHERE news.active=2";
          $cfg_current = 10;
 
un'altro problema.. per far che la visualizzazioni instante quella che si vede appena accedi .. vorrei mettere active=1.,
ma mi da un syntax error .. perché la query e scritta male.

ora ti posto il codice:
PHP:
$query = "SELECT utenti._user as _user , news_categorie.titolo as _cat , news.* FROM utenti 
       INNER JOIN news 
          ON utenti.id = news._userid INNER JOIN news_categorie 
          ON news_categorie.id = news._catid "; // QUI SE  METTO WHERE etc.. AND mi da errore di sintassi sql.

if(!empty($_GET['cat'])) {
          $query.="WHERE _catid=".(int)$_GET['cat'];
          $cfg_current = $cfg_news_list_cat_admin;
}elseif(!empty($_GET['uid'])){
          $query.="WHERE news._userid=".(int)$_GET['uid'];
          $cfg_current = $cfg_news_list_utenti_admin;
}elseif(!empty($_GET['a']) && $_GET['a']=='trash'){ 
          $query.="WHERE news.active=4"; 
          $cfg_current = 10; 
}elseif(!empty($_GET['a']) && $_GET['a']=='hidden'){ 
          $query.="WHERE news.active=2"; 
          $cfg_current = 10; 
}
    $pag = new Paginazione($query,$cfg_current, $pagina);

ti ringrazio e buone feste.
 

Discussioni simili