简体   繁体   English

Codeigniter表联接然后显示标签问题

[英]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. 换句话说,如果一个帖子有7个标签,则该帖子的7个迭代分别带有一个标签,而不是1个带有7个标签的迭代。

My Controller ( do have a question about the $this->db->get(posts, tags) is that correct 我的控制器(确实对$ this-> db-> get(posts,tags)有疑问吗?

$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; $ limit = 5; // how many posts should we show in full? //我们应完整显示多少篇文章? $i = 1; $ 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. 这是我第一次尝试使用join,如果那是正确的方法,那么我几乎没有经验来使显示发生内爆。

Thank you in advance. 先感谢您。

Try 尝试

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

and remove the 2 rows before this one. 并删除前两行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM