2010-11-13 7 views
0

Bonjour j'ai cette jointure, mais je veux rejoindre un autre Tabel nommé « utilisateurs » et je veux la « profil_billed » ligne, comment puis-je faireCodeIgniter rejoint plusieurs

je veux dire « Où forum_traad.brugernavn = utilisateurs. profil_billed » quelque chose comme ça

function posts($id) 
{ 
    $this->db->select('*,forum_traad.indhold as traad_indhold, 
         forum_kommentare.indhold as kommentare_indhold, 
         forum_traad.brugernavn as traad_brugernavn, 
         forum_traad.id as traad_id 
         '); 
    $this->db->from('forum_traad'); 
    $this->db->join('forum_kommentare', 'forum_kommentare.fk_forum_traad', 'forum_traad.id'); 
    $this->db->where('forum_traad.id', $id); 

    $query = $this->db->get(); 

    if($query->num_rows > 0) 
    { 
     return $query->row(); 
    } else { 
     return false; 
    } 

} 
+0

quelque chose comme ça $ this-> db-> rejoindre ('utilisateurs', 'forum_traad.brugernavn', 'users.username'); – Simon

+0

mais ça ne marche pas et puis-je avoir 2 jointures comme ça? – Simon

Répondre

0

Vous pouvez écrire votre requête comme ci-dessous -

$this->db->select('*,forum_traad.indhold as traad_indhold, 
         forum_kommentare.indhold as kommentare_indhold, 
         forum_traad.brugernavn as traad_brugernavn, 
         forum_traad.id as traad_id, users.profil_billed as billed 
         '); 
    $this->db->from('forum_traad'); 
    $this->db->join('forum_kommentare', 'forum_kommentare.fk_forum_traad = forum_traad.id'); 
    $this->db->join('users', 'forum_traad.brugernavn = users.profil_billed'); 
    $this->db->where('forum_traad.id', $id); 
    $query = $this->db->get(); 

Pour une documentation détaillée de la syntaxe que j'ai utilisé ci-dessous renvoient -

http://codeigniter.com/user_guide/database/active_record.html

+0

ça ne marche pas ça va à mon autre dans mon fichier de vue qui ressemble à ceci: http://pastebin.com/45muaLLY – Simon

+0

Obtenez-vous une erreur mysql ou zéro lignes retournées? Avez-vous besoin d'une jointure non naturelle, comme une jointure à gauche? – Natebot

+0

je reçois seulement ce "Der blev ikke fundet nogen tråd" et c'est mon autre, donc non .. je ne sais pas si j'ai besoin de rejoindre à gauche – Simon