douduan2272 2014-11-25 03:32
浏览 58

cake php:某些id的HTML链接?

I'm new to CakePHP, I was wondering if there is a way to echo information from the database using a foreach loop but only have HTML links on images where the id is 1 & 7. What's the best way of achieving this?

<?php if ( isset($articles) ){ ?>
        <?php foreach($articles as $article):?>
        <?php echo ($this->Html->image($article['Post']['picture'], array('alt' =>    'storyimage', 'class' => 'smallimg'));?>
        <h3 class="caps"><?php echo $article['Post']['genre'];?></h3>
        <h2><?php echo $article['Post']['story'];?></h2>
        <div id="contentbox2">
        </div>
        <?php endforeach; ?>
        <?php } ?>

This is how it looks in the veiw, my database in looks image data is stored like this: suki-burberry-sq_500_500_90_s_c1.jpg Would it be best to echo all the data individually without the foreach loop or could I write an if statement?

  • 写回答

2条回答 默认 最新

  • dongzhanjuan5141 2014-11-25 03:59
    关注

    If you want only to get the 1 & 7 id you can do this, assuming that it is a predefined number. If it is dynamic or changeable you can do that in your controller.

    <?php if ( isset($articles) ){ ?>
    
            <?php foreach($articles as $article):?>
    
            <?php if ($article['Post']['id']==1 || if ($article['Post']['id']==7) ): ?>
    
            <?php echo ($this->Html->image($article['Post']['picture'], array('alt' =>    'storyimage', 'class' => 'smallimg'));?>
            <h3 class="caps"><?php echo $article['Post']['genre'];?></h3>
            <h2><?php echo $article['Post']['story'];?></h2>
            <div id="contentbox2">
            </div>
    
            <?php endif; ?>
    
            <?php endforeach; ?>
            <?php } ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗