Welcome Guest, Not a member yet? Register   Sign In
[question - solved] Join - active record

oks i couldnt find any awnser for this in the forum.

        $this->db->join('articles', 'articles.author_id = users.user_id');
        return $this->db->get();

I'm trying to get a username and all i get is this ->
Quote:Object id #19

any idea why?it should give me the name.


[eluser]Michael Wales[/eluser]
It's doing what it should - it's returning the result object that you requested.

Now you need to do something with that result object, like:

if ($query->num_rows() > 0) {
  $row = $query->row();
  echo $row->username;

User Guide: Generating Query Results

...ok...to me -> "DUH!" lol
stupid me xD

thanx for the tip wales Smile

oks, i'm doing something really stupid.

what I'm trying to get is the username,

I've got a table for articles where we can find a author_id,
i wanna list all articles showing title, author name and publish date.

to get the article info is everything ok and shows it all.

how should i get the username?

my first idea was to do a 2nd function in articles model where i would get
the username but i forgot that i do a foreach in the view, what happens is that
it gives the same username for all of them.

so probably i should merge the get articles function with the get author
do a join and foreach one time right?

any tip?

p.s- I'm really slippy so sorry for the confusion

ok...and again...DUH... lol
i really need a sleep.

for those who need an answer for this,
this is what i did and works Smile

$this->db->select('lab_users.username,lab_articles_categories.category_title, lab_articles.*');
        $this->db->join('users', 'articles.author_id = users.user_id');
        $this->db->join('articles_categories', 'articles.category_id = articles_categories.category_id');
        $this->db->orderby('article_id', 'asc');
        return $this->db->get('articles');

One thing I do in my models:


$data = $this->db->get('table');

return $data->result();

No sense in returning the result object when you can just return the data and start manipulating it right off the bat.


function countup($link_id) {
        $this->db->query('UPDATE awLinks SET link_clicks = (link_clicks + 1) WHERE link_id = '.$link_id);
        $this->db->select('link_url')->where('link_id', $link_id);
        $link = $this->db->get('awLinks');
        return ($link->num_rows() > 0) ? $link->row() : FALSE;

Theme © iAndrew 2016 - Forum software by © MyBB