gpt4 book ai didi

php - codeigniter 重复 FOREACH

转载 作者:行者123 更新时间:2023-11-29 22:41:06 25 4
gpt4 key购买 nike

我正在尝试从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com