これは私のコードの例です。私は仕事をする必要があります...foreachでリターンを使用すると、medooでエコーされない
"echo '...'を使用すると、 return '...'; "私はレコードを1つだけ取得します。エコーを使用したくないという問題は、私のページの上にすべての結果を得ることです。私は私のページのどこかにこの関数を呼び出すので、私はリターンを使用する必要があります。
ありがとうございます!
public function showForum()
{
$cats = $this->db->query("SELECT * FROM forum_cats ORDER BY cat_order ASC")->fetchAll();
foreach ($cats as $cat) {
return '<table class="table forum table-striped">
<thead>
<tr>
<th class="cell-stat"
style="background-image: url(\'\'); background-size: 50px; background-repeat: no-repeat; background-position: center;"></th>
<th>
<h3>' . $cat['cat_name'] . '</h3>
</th>
<th class="cell-stat text-center hidden-xs hidden-sm">Topics</th>
<th class="cell-stat text-center hidden-xs hidden-sm">Posts</th>
<th class="cell-stat-2x hidden-xs hidden-sm">Last Post</th>
</tr>
</thead>
<tbody>
<tr>
<td class="text-center"><i class="fa fa-question fa-2x text-primary"></i></td>
<td>
<h4><a href="#">Frequently Asked Questions</a><br>
<small>Some description</small>
</h4>
</td>
<td class="text-center hidden-xs hidden-sm"><a href="#">9 542</a></td>
<td class="text-center hidden-xs hidden-sm"><a href="#">89 897</a></td>
<td class="hidden-xs hidden-sm">by <a href="#">John Doe</a><br>
<small><i class="fa fa-clock-o"></i> 3 months ago</small>
</td>
</tr>
</tbody>
</table>';
}
}
はい、「return」は関数の実行を終了するためです。ループの代わりに、文字列を配列項目に設定し、ループの後に配列を返します。後でエコーアウトすることができます。 –
それぞれを配列に格納するようにコメントを編集しました。別のオプションは、文字列を連続して連結し、最後の文字列を返すことです。 –
提案ありがとうございました@JonStirling! :) – 7h3ev1l