【问题标题】:Show tags and an associative id显示标签和关联 ID
【发布时间】:2014-05-11 10:12:09
【问题描述】:

我有一个问题...我想通过回显显示 tag_name 和 id: 我的数组:

 Array
 (
 [id] => 15
 [title] => This is the first article
 [content] => 

This is the first articleThis is the first articleThis is the first articleThis is the    first articleThis is the first articleThis is the first articleThis is the first articleThis is the first articleThis is the first articleThis is the first articleThis is the first articleThis is the first articleThis is the first articleThis is the first articleThis is the first articleThis is the first articleThis is the first article

[date] => 2014-05-11 12:05:00
[views] => 0
[smallimage] => Hydrangeas-11.jpg
[largeimage] => Hydrangeas-11.jpg
[tags] => first tag,last tag,second tag
[id_tag] => 15,16,17
)

我试过了,但是当我链接时,我进入浏览器:localhost/blogCI/tag/15,16,17 但我需要显示 localhost/blogCI/tag/15 或 localhost/blogCI/tag/16 我的代码:

<div class="news-content-title">
            <? echo $main_info['title'];?>
        </div>
        <div class="news-content-content">
            <? echo $main_info['content'];?>
        </div>


        <?php foreach($main_info as $n):?>
                        <?php $tags = explode(",", $n['tags']); ?>
                        <?php $id_tag = explode(",", $n['id_tag']); ?>

        <?php endforeach ?>
        <?php for ($i=0;$i<count($id_tag);$i++): ?>

                    <a href="<?php echo base_url('tag/'.$main_info['id_tag'])?>"><?php echo $main_info['tags'] ?></a>

        <?php endfor; ?>

请帮帮我

【问题讨论】:

    标签: php codeigniter codeigniter-2 php-5.3


    【解决方案1】:

    我对语法不是特别确定,因为我没有使用过 codeigniter,但你可以试试这个:

    <?php
          $tags['tags'] = explode(",",$main_info['tags']);
          $tags['id_tag'] = explode(",",$main_info['id_tag']);
    
             foreach($tags['tags'] as $k=>$v): ?>
               <a href="<?php echo base_url('tag/'.$tags['id_tag'][$k])?>"><?php echo $v ?></a>
             <?php endforeach ?>
    

    【讨论】:

    • @user3613935 你能在foreach之前print_r($tags);吗?
    • 数组 ( [0] => 1 ) 数组 ( [0] => T ) 数组 ( [0] => 2 ) 数组 ( [0] = > 1 ) 数组 ( [0] => H ) 数组 ( [0] => H ) 数组 ( [0] => f ) 数组 ( [0] => 1 )
    • @user3613935 哎呀,我以为它是一个数组,试试编辑的代码。
    • 现在在视图中打印:1 A
    • 它从数组的所有组件中获取第一个
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多