开发者

Codeigniter table Join then Display Tags Problem

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.


Try

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

and remove the 2 rows before this one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜