Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
J'ai un systéme de catégories et sous catégories
Ex : 
1/ 
catégorie : Sport
sous catégorie : foot,hand,bascket...
2/
catégorie : loisirs
sous catégorie : jeux, chat ...
dans j'ai deux tables categorie(id,libelle) et sous_categorie(id,libelle,#id_catégorie)
j'ai fait deux fonctions :
get_categorie() et get_souscategorie(id_categorie)
get_souscategorie est appeler dans get_categorie pour récupérer les sous catégories d'une catégorie.
La fonction GET_CATEGORIE()
    public static function get_categorie() {
        global $db;
        $tab = array();
        
        $req="select * from categorie" ;
    
        try {
            $result = $db->fetchAll( $req );
            foreach ( $result as $k => $v ) {
                    $tmp = new Categorie();//nouveau objet categorie
                $tmp->id = $v['id'];
                $tmp->libelle = $v['libelle'];
                $tab[] = $tmp;
                
                $s = new Souscategorie();//nouveau objet sous categorie
                $tab[][] = $s->get_souscategorie($v['id']);
            }
            echo print_r($tab[1])."<br/><br/>";
            return $tab;
        } catch (Exception  $e){
                echo($e->getMessage());
        }
    }la fonction GET_SOUSCATEGORIE()
public function get_souscategorie($idx){
        
        global $db;
        $t = array();
        $req = 'select * from sous_categorie INNER JOIN categorie ON sous_categorie.id_catgeorie = categorie.id where id_categorie='.intval($idx)."";
        try{
            $result = $db->fetchAll( $req );
            
            foreach($result as $j => $w){
                $tm = new sous_categorie;
                $tm->id = $w['id'];
                $tm->libelle = $w['libelle'];
                $tm->contenu = $w['contenu'];
                $tm->id_chapitre = $w['id_chapitre'];
                $t[] = $tm;
                //echo var_dump($tm)."<br><br>";
            }    
            return $t;
            
        }
        catch(exception $e){
            echo($e->getMessage());
        }
    }Voilà je veux récupérer sous la forme d'un menu à l'aide de smarty. Merci
Dernière modification par zizou86 (22-05-2009 00:49:55)
Hors ligne