views:

23

answers:

1

I have a problem that concerns blog posts and displaying the tag words from another table. I seem to be able to pull the info out of the tables fine, however when I try to display the posts and the tags, I get one tag per post. In other words if I have 7 tags for a post, I get 7 iteration's of that post each with one tag instead of 1 post with 7 tags.

My Controller ( do have a question about the $this->db->get(posts, tags) is that correct

$this->db->order_by('posts.id', 'DESC');
$where = "publish";
$this->db->where('status', $where);
$this->db->join('tags', 'tags.post_id = posts.id');
$this->db->limit('7');
$query = $this->db->get('posts', 'tags');
if($query->result())
    $data = array();
    {
        $data['blog'] = $query->result();
    }
    $data['title'] = 'LemonRose';
    $data['content'] = 'home/home_content';

    $this->load->view('template1', $data); 

The view. $limit = 5; // how many posts should we show in full? $i = 1; // count

foreach ($blog as $row):
$permalink =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];
$url = CompressURL ("$permalink");
$description = $row->title  .   $row->post;
$twittermsg = substr($description, 0, 110);
$twittermsg .= "...more " .  $url; 
if ($i < $limit) // we are under our limit
    { ?>

<div class="titlebox">
<div class="title"><? echo ucwords($row->title); ?></div>
<span><? echo $row->date, nbs(10), $row->author; ?></span> 
</div>
<div class="clear"></div>
<? $str = str_word_count($row->post, 0);
    if ($str >= 500) {
    $row->post = html_entity_decode($row->post);
    $row->post = $this->typography->auto_typography($row->post); // display?>
 <div class="split"> <? echo $row->post = word_limiter($row->post, 480); ?> 


 <div class="tags"><? echo $row->tag; ?></div>*** These 3 lines seem to be where I am confused and getting the wrong display


 <p><h3>More <?php echo anchor("main/blog_view/$row->id", ucwords($row->title)); ?>    </h3></p>  
 <p>Trackback URL: <? echo base_url() . "trackbacks/track/$row->id"; ?></p>  
 <!-- tweet me -->    
<?echo anchor("http://twitter.com/home?status=$twittermsg", 'Tweet'); ?> 

This is my first attempt with join and I have very little experience getting the display with implode, if that is the right way to go.

Thank you in advance.

A: 

Try

<div class="tags"><? echo implode(', ', $row->tag); ?></div>

and remove the 2 rows before this one.

DrColossos
In doing that I get the following error. "Message: implode() [function.implode]: Invalid arguments passed". Is it possible that $row->tags has not been prepped as an array? Or should it be passed differently than the rest of the $row-> tags that went through the foreach statement?(not shown) Let me add the rest of the view to the post above.
Brad
just print it put (with `print_r`) and check if there is something in there. If not, you know that you need to populate the variable differently.
DrColossos
Print_r gives me the same problemsNo doubt about it, I cant see how that variable can go through Foreach as an array so you are right, I will find a different way to populate the array. Thank you
Brad