문제

I have a problem...I want to show with an echo the tag_name an the id: My array:

 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
)

I tried, but when I link I get in brower: localhost/blogCI/tag/15,16,17 but I need to show localhost/blogCI/tag/15 or localhost/blogCI/tag/16 My code:

<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; ?>

Help me please

도움이 되었습니까?

해결책

I'm not particularly sure about the syntax as I haven't worked with codeigniter but you could try this:

<?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 ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top