[eluser]gmask[/eluser]
Hello, I'm having a really hard time getting the results I want from the database. Here's what I'm trying to do: I have an entries view that lists all of the entries in my database. In each of these entries is a field called 'category' which points to the `categories` table. I would like to be able to have the ability to show which category my entry was posted in, but I can't seem to get it working. Here's the way I'm going about it, please correct me if I'm being silly:
This is in my model
Code:
function entries($num, $offset)
{
$query = $this->db->query("SELECT categories.title, categories.id, entries.* FROM entries,categories WHERE entries.category=categories.id ORDER BY entries.type DESC, entries.id DESC LIMIT $num");
return $query;
}
This is the relevant section of my controller
Code:
function entries()
{
$config['base_url'] = base_url().'/entries/';
$config['total_rows'] = $this->db->count_all('entries');
$config['per_page'] = '10';
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->load->model('fetch_model');
$data['entries'] = $this->fetch_model->entries($config['per_page'],$this->uri->segment(3));
$this->template->load('templates/default', 'entries', $data);
}
This is the relevant section of my view
Code:
<?php foreach($entries->result() as $entry) { ?>
<div class="result">
<p class="left-title"><?php echo anchor('edit_entry/'.$entry->id, $entry->title); ?></p>
<p class="right-title"><?php echo anchor('edit_category/'.$entry->category, 'Parent'); ?></p>
</div>
<?php } ?>
Obviously I'd like to be able to echo the category title field in the anchor, replacing the 'Parent' text.
What's the best way to do this?