Welcome Guest, Not a member yet? Register   Sign In
Need help to retrieve some datas between tables in one query [SOLVED]
#1

[eluser]Ludovic-r[/eluser]
Hi !

I'm stuck with something that I can't fix and need your help, let me explain my configuration :

I have 3 TABLES :

TABLE #1 : called post
TABLE #2 : called categories
TABLE #3 : called post_categories

In my TABLE #1 I have some fields like id, text, title, date and so on
In my TABLE #2 I have id and category_name
In my TABLE #3 I link the post_id with the category_id

This is for the MySQL part.

Now I would retrieve my TABLE #1 entire informations and link my TABLE #2 category_name informations within the post
So to do that I've created TABLE #3 which make the link between post and category

The problem is that I can't retrieve my informations I don't know why :/

I've tried that :

Code:
$this->db->select('*');
        $this->db->from('post');
        $this->db->join('categories', 'post_categories.post_id = post_categories.category_id');
        $this->db->where('post.id', 'post_id');
        $this->db->order_by('rank', 'asc');
        
        $q = $this->db->get();
        
        return $q->result();

Oh and one another thing, If I need to DELETE once the category_name and the occurence in the TABLE #3 is it possible? I heard something like ON CASCADE but don't really know how to use it.

Any idea and help would be very very appreciated!

Thanks! (Sorry for my poor english)


Messages In This Thread
Need help to retrieve some datas between tables in one query [SOLVED] - by El Forum - 06-11-2011, 02:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB