[eluser]georgerobbo[/eluser]
Hello,
I am trying to connect blog posts with their related tags. My database structure is as follows.
table: tag
ID Int // This is the Primary Key
post Int // This is the ID of each blog post
tag Varchar // This is the tag
table: post
ID Int // Primary Key
Title Varchar
Author Varchar
Timestamp Varchar
Filename Varchar
Description Varchar
Category Varchar
Comments Varchar
Favourites Varchar
Views Varchar
My problem is that when I join the tables, only the first tag for each post is selected, rather than all of them.
My model, controller and view are:
Code:
function the_post($permalink)
{
$this->db->select('*');
$this->db->from('post');
$this->db->join('tag', 'post.ID = tag.post');
$this->db->where('post.ID', $permalink);
$query = $this->db->get();
return $query->result_array();
}
Code:
function single()
{
$permalink = $this->uri->segment(2);
$data['current'] = $this->Post->the_post($permalink);
foreach ($data['current'] as $a):
$id = $a['ID'];
$count = $a['views'];
$data['title'] = $a['title'];
endforeach;
if(isset($id)) {
$data['count'] = $this->Post->count_view($id, $count);
}
$this->load->view('meta', $data);
$this->load->view('header', $data);
$this->load->view('single', $data);
}
Code:
<div id="page">
<?php foreach ($current as $a): ?>
<div id="preview" class="extended">
<div id="preview_item" class="extended">
<img src="<?php echo base_url() . " align="center" alt="" />
</div>
</div>
<div id="meta" class="extended">
<h2><a href="<?php echo site_url(); ?>/id/<?php echo $a['ID']; ?>"><?php echo $a['title']; ?></a></h2>
<h5><small>Author:</small> <a href="<?php echo site_url(); ?>/profile/<?php echo $a['username']; ?>"><?php echo $a['author']; ?></a></h5>
<h5><small>Uploaded:</small> <?php $timestamp = strtotime($a['timestamp']); $timestamp = date('F j, Y', $timestamp); echo $timestamp; ?></h5>
<h5><small>Tags:</small><?php echo $a['tag']; ?></h5>
<h5><small>Category:</small><?php if(isset($a['category'])) { echo $a['category']; } else { echo "None"; } ?></h5>
<p class="extended"><small><?php echo $a['description']; ?></small></p>
<p class="ref"><small><?php echo $a['comments']; ?> comments</small></p>
<p class="ref"><small><?php echo $a['favourites']; ?> favourites</small></p>
<p class="ref"><small><?php echo $a['views'] + 1;?> views</small></p>
</div>
<?php endforeach; ?>
</div>