Welcome Guest, Not a member yet? Register   Sign In
Join statements going wrong.
#1

[eluser]Ferdy[/eluser]
Ok, I did some searching, and while I did find some posts with people who needed help with a join, they weren't similar to my problem so here goes.

I'm trying to make a simple news posting system. My posts table has the following fields:

id - this is the id of the post, naturally
postTitle - a field containing the title of the post
postShort - a field containing a short intro for the front page
postFull - a field containing the entire post
postedOn - the date on wich the post was made
postedBy - the id of the user who made the post
postCategory - the id of the posts'category
updatedOn - the date on wich the post was updated
updatedBy - the id of the user who updated the post

Ok, seems pretty simple. Now, here we go.


This piece of code works as intended. It gives me acces to the username and email of the one who made the post. And allows me to show all posts, again, just as intended.

Code:
$this->db->select('posts.*, user.username as poster, user.useremail as posteremail');
$this->db->order_by("posts.id", "desc");
$this->db->join('user as user1', 'user1.id = posts.postedBy');

this piece of code however, does not work as intended:

Code:
$this->db->select('posts.*, user.username as poster, user.useremail as posteremail, user2.username as updater, user2.useremail as updateremail');
$this->db->order_by("posts.id", "desc");
$this->db->join('user', 'user.id = posts.postedBy');
$this->db->join('user as user2', 'user2.id = posts.updatedBy');

It doesn't give me any errors or anything, however, when I use that piece of code, it only shows me posts that have been updated wich, naturally, is not what I want. I want all posts to show, and in a post that has been updated I just want to say something like "this post has been updated by bla bla..."

I tried right, left, outer, inner combinations of all sorts, but nothing is working. So, what is it that I am doing wrong?

To whoever can help me, thanks in advance.

-Ferdy


Messages In This Thread
Join statements going wrong. - by El Forum - 09-13-2008, 06:09 AM
Join statements going wrong. - by El Forum - 09-13-2008, 01:00 PM
Join statements going wrong. - by El Forum - 09-13-2008, 01:41 PM
Join statements going wrong. - by El Forum - 09-13-2008, 01:49 PM
Join statements going wrong. - by El Forum - 09-13-2008, 01:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB