Reputation: 1
i have 2 tabels in my database "forum_traad" and "forum_kommentare" but they have the same row "indhold" so when i try to join forum_traad and forum_kommentare and i wanna echo the "indhold" row from "forum_traad" it echo the "indhold" from "forum_kommentare", what can i do?
my view:
<div id="forum">
<?php
if($query)
{
?>
<div class="forum_headline">Forum kategori - Forum tråde - <?php echo $query->overskrift; ?></div><!-- forum_headline -->
<div class="forum_profil_img"></div><!-- forum_profil_img -->
<div class="forum_post_content">
<span style="font-size:15px;"><?php echo anchor('profil/'.$query->brugernavn, $query->brugernavn); ?></span>
<span style="font-size:11px; margin-left:3px; color:#686868;"><i> Siger</i></span><br>
<?php echo $query->indhold;
echo "<br>ID: ".$query->id;
?>
</div><!-- forum_post_content -->
<?php
} else {
echo "Der blev ikke fundet nogen post";
}
?>
</div><!-- forum -->
My model
function posts($id)
{
$this->db->select('*');
$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;
}
}
Upvotes: 0
Views: 171
Reputation: 33658
You can give them a different name:
$this->db->select('forum_traad.indhold as traad_indhold,
forum_kommentare.indhold as kommentare_indhold');
If you need the functionality of * you can in addition select:
$this->db->select('forum_traad.indhold as traad_indhold,
forum_kommentare.indhold as kommentare_indhold,
forum_traad.*,
forum_kommentare.*');
Upvotes: 1