• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to join tables to display the author of blog entry

#3
[eluser]Brad Morse[/eluser]
This is what I came up with with a little digging thru the forums:

Please let me know if there is a better way to do this:

Code:
Controller

<?php
function index() {

    $data['title'] = "My Blog Title";
    $data['heading'] = "My Blog Heading";
    //$data['query'] = $this->db->get('entries');
    
    $this->db->select('*');
    $this->db->from('entries');
    $this->db->join('authors', 'authors.id = entries.author_id');
    $data['query'] = $this->db->get();
    
    $this->load->view('blog_view', $data);
}
?>

View

<?php foreach($query->result() as $row): ?>
    <h2>&lt;?=$row->title?&gt;</h2>
    &lt;?php
        $body_text = $row->body;
        print character_limiter($body_text, 210);
    ?&gt;
    <p>Author: &lt;?=$row->first_name.' '.$row->last_name?&gt;</p>
    <p>&lt;?=anchor('blog/more/'.$row->id, 'Read on');?&gt;</p>
    <p>&lt;?=anchor('blog/comments/'.$row->id, 'Comments');?&gt;</p>
    <hr>
&lt;?php endforeach; ?&gt;


Messages In This Thread
Trying to join tables to display the author of blog entry - by El Forum - 12-11-2008, 09:34 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.