我正在编写一个 MyBB 插件。它现在可以工作了,但是我在尝试循环代码集时遇到了一些问题。
例如。我正在使用此代码从数据库中获取数据。
//Some codes...
$lctg_rcposts .= '
<div class="bt-lite">
<div class="bt-link">Newest Posts</div>
<div id="bt-holder">';
$count = $db->simple_select("threads", "COUNT(tid) AS threads", "$uview");
$threadcount = $db->fetch_field($count, "threads");
$sets = $threadcount / $totalsets;
for ($i=1; $i<=$sets; $i++)
{
$lctg_rcposts .= '<div class="bt-set">';
$query = $db->query("SELECT t.*
FROM ".TABLE_PREFIX."threads AS t
$ufids AND t.visible = '1' GROUP BY t.tid
ORDER BY t.lastpost DESC LIMIT 3"
);
while($data = $db->fetch_array($query))
{
$datacache['tid'] = $data;
}
if(!empty($datacache))
{
foreach($datacache as $data)
{
//Some code...
$lctg_rcposts .= '
<a href="thread-' . $data['tid'] . '-lastpost.html">
' . $subject .'
</a>';
}
}
$lctg_rcposts .= '</div>'; //--- End of Sets
}
$lctg_rcposts .= '</div></div>'; //--- End of File
问题是每组的内容都是一样的(当然)。但我想这将有如下模型。(一套好的只有3个链接)
<div class="bt-set>
<a>1</a>
<a>2</a>
<a>3</a>
</div>
<div class="bt-set>
<a>4</a>
<a>5</a>
<a>6</a>
</div>
... and goes on ...
请给我一些建议。十分感谢。