Welcome Guest, Not a member yet? Register   Sign In
Blog Database Structure - Categories & Meta Tags
#14

[eluser]lenwood[/eluser]
I figured it out. Somehow it just made sense to me when I sat down at my computer tonight.

I'm calling the category names in two views, a listing of all of my blog entries and on the individual posts. Here's my code:

Listing of all blog entries:
Code:
function list_all_blog_entries()
{
    $this->db->select("*, date_format(date_time, '%W, %M %e, %Y') as date", FALSE);
    $this->db->order_by('date_time', 'desc');
    $this->db->join('post_cat', 'post_cat.entry_id = entries.id');
    $this->db->join('categories', 'categories.id = post_cat.cat_id');
    $query = $this->db->get('entries');

    if($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $this->db->like('entry_id', $row->id);
            $row->num_comm = $this->db->count_all_results('comments');
            $data[] = $row;
        }
    }
    return $query->result();
}

Single blog post
Code:
function single()
{
    $this->db->select("*, date_format(date_time, '%W, %M %e, %Y') as date, date_format(date_time, '%l:%i %p') as time", FALSE);
    $this->db->where('post_slug', $this->uri->segment(3));
    $this->db->join('post_cat', 'post_cat.entry_id = entries.id');
    $this->db->join('categories', 'categories.id = post_cat.cat_id');
    $query = $this->db->get('entries');
    
    if($query->num_rows() > 0) {
        $row = $query->row_array();    
        return $row;
    }
}

This code works, I'm able to call the category names directly. All feedback on my code is welcome. I'll take this as a sign that there's value in slogging through something that you don't understand, trusting that it will become clear at some point.


Messages In This Thread
Blog Database Structure - Categories & Meta Tags - by El Forum - 04-19-2010, 06:51 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 04-19-2010, 07:36 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 04-19-2010, 07:48 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 04-19-2010, 08:15 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 04-19-2010, 09:18 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 04-19-2010, 04:32 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 04-19-2010, 06:58 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 04-19-2010, 07:05 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 04-20-2010, 07:11 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-03-2010, 10:11 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-03-2010, 11:54 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-03-2010, 02:05 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-03-2010, 02:30 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-03-2010, 06:01 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-03-2010, 08:42 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-04-2010, 02:02 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-04-2010, 09:58 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-04-2010, 10:10 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-04-2010, 12:05 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-04-2010, 12:21 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-04-2010, 07:05 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-04-2010, 08:38 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-06-2010, 09:17 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-06-2010, 11:50 AM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-06-2010, 12:15 PM
Blog Database Structure - Categories & Meta Tags - by El Forum - 05-06-2010, 02:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB