Welcome Guest, Not a member yet? Register   Sign In
issue with using join

Here is a method from one of my models:

function get_newest($limit = NULL, $offset = NULL){
            $this->db->join('states', 'states.id = entries.state_id');
            $this->db->order_by('entries.timestamp', 'desc');
            return $this->db->get();

This is causing some real issues and I'm sure there is a simple solution. I have 2 tables. `entries` and `states`. Both have a field called `id`. Here is the code I'm using to display entries:

see below...

since both tables have `id` as a field, it's pull the data from states and breaking my app. I'm very unfamiliar with JOINs outside of CI so any help would be great. How can I specify that I want the `id` field from `entries, not `states`

If there is any information I've left out that will help, please let me know.


For some reason the CI forum tries to parse what I'm pasting in so the code won't display correctly. Also, I can't attach a file renamed view_name.txt as the mime type is incorrect. Wow, I think breaking my own fingers would be more enjoyable than this. OK. So I'm using a pastebin to get this posted. Ridiculous.


[eluser]Matthieu Fauveau[/eluser]

Why not use $this->db->select('entries.id AS id'); ?

That worked! Database work is by far my weakest point. Thanks for the help.

[eluser]Matthieu Fauveau[/eluser]
No problem, glad to be of help from times to times Wink

Theme © iAndrew 2016 - Forum software by © MyBB