php - codeigniter 重复 FOREACH

标签 php mysql codeigniter frameworks

我正在尝试从 mysql 获取一些数据,例如论坛名称评论数量。

我的代码看起来像这样

<?php foreach(fetch('forum_threads', 'limit=5') as $forum_thread) : ?>
  <?php foreach(fetch('forums', 'limit=5') as $forum) : ?>
    <?php foreach(fetch('forum_sections', 'limit=5') as $forum_section) : ?>
      <li>
        <img src="/themes/<?php echo setting('themes.default_theme') ?>/assets/images/ico/neo-white.png">
        <a href="#comments" class="comments anim-01"><span class="anim-01"><?= $forum_thread->forum_posts_number ?></span></a>
        <h3><a href="./forums/<?= $forum->url_name ?>/<?= $forum_thread->id ?>/<?= $forum_thread->url_title ?>"><?= $forum_thread->title ?></a></h3>
        <span class="meta"><a href="./articles/<?= $article->section->url_name ?>"><?= $forum_section->name ?></a> - <abbr class="timeago" title="<?= $forum_thread->created_at ?>"><?= $forum_thread->created_at ?></abbr></span>
      </li>
    <?php endforeach; ?>
  <?php endforeach; ?>
<?php endforeach; ?>

一切看起来都正常,但我有 5 个相同的论坛主题:

    HELLO
    HELLO
    HELLO
    HELLO
    HELOO
    HELLO2
    HELLo2
    HELLO2
    HELLO2
    HELLO2

我想做的事情看起来像这样:

HELLO
HELLO2. 

抱歉我的英语不好,感谢您的回答!干杯

最佳答案

做:

<?php foreach(fetch('forum_threads', 'limit=5') as $forum_thread) : ?>

然后打印您的论坛主题名称,然后:

<?php foreach(fetch('forums', 'limit=5') as $forum) : ?>

然后打印您的论坛 URL,然后:

<?php foreach(fetch('forum_sections', 'limit=5') as $forum_section) : ?>

然后打印您的论坛部分名称。最后关闭所有的foreach。

关于php - codeigniter 重复 FOREACH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29348117/

相关文章:

php - MySql 自适应 ID

php - Codeigniter 是否有可扩展的多站点策略?

php - php 中的扩展不起作用

mysql - mysql表中使用TEXT字段的问题

mysql - 如何克服 ERROR 1045 (28000) : Access denied for user 'ODBC' @'localhost' (using password: NO) permanently

mysql - RDBMS MySQL 中的 sqoop 导出更新表记录

php - CodeIgniter 的电子邮件编码不正确

php - 使用 jQuery 和 Codeigniter 进行表单验证?

php - 全日历事件在 9 点之前不显示

php - Mysql检查是否已经过了30分钟