我正在使用xTemplate类
我的PHP代码:
$sql = $database->query('SELECT * from os_forumcats ORDER BY orderby ASC');
foreach($sql as $row):
$template->assign(array(
'FORUMS_ID' => $row['id'],
'FORUMS_TITLE' => $row['title'],
'FORUMS_DESCRIPTION' => $row['description'],
));
$template->parse('MAIN.FORUMS_ROW');
endforeach;
我的模板代码:
<table>
<!-- BEGIN: FORUMS_ROW -->
<tr>
<td>{FORUMS_ID}</td>
<td>{FORUMS_TITLE}</td>
<td>{FORUMS_DESCRIPTION}</td>
</tr>
<!-- END: FORUMS_ROW -->
</table>
如何显示子论坛?
我的表:
我的分类
答案 0 :(得分:0)
您可以尝试以下(未测试)。 PHP代码可以是: [根据您的评论更新此代码]
$sql = $database->query('SELECT * from os_forumcats WHERE parentid = 0 ORDER BY orderby ASC');
foreach ($sql as $row):
$template->assign(array(
'FORUMS_ID' => $row['id'],
'FORUMS_TITLE' => $row['title'],
'FORUMS_DESCRIPTION' => $row['description'],
));
$template->parse('MAIN.FORUMS_ROW');
$subquery = $database->query('SELECT * from os_forumcats WHERE parentid = $row["parentid"] ORDER BY orderby ASC');
foreach ($subquery as $subrow):
$template->assign(array(
'SUBFORUMS_TITLE' => $subrow['title'],
));
$template->parse('MAIN.SUBFORUMS_ROW');
endforeach;
endforeach;
模板代码:
<table>
<!-- BEGIN: FORUMS_ROW -->
<tr>
<td> {FORUMS_ID}</td>
<td>{FORUMS_TITLE}<br />
<!-- BEGIN: SUBFORUMS_ROW -->
{SUBFORUMS_TITLE},
<!-- END: SUBFORUMS_ROW -->
</td>
<td>{FORUMS_DESCRIPTION}</td>
</tr>
<!-- END: FORUMS_ROW -->
</table>