【发布时间】:2013-12-31 13:08:23
【问题描述】:
大家好,各位大师。
这可能是最简单的事情,但我正在努力寻找答案。
基本上,我有两个表,结构如下:
表 1:
categories_docs
| CATID | parent | name |
| 1 | 0 | Cars |
| 2 | 0 | Bikes |
| 3 | 1 | VW |
| 4 | 1 | Toyota |
| 5 | 2 | Honda |
| 6 | 2 | Yamaha |
表2:
docs
| DOCID | categories | title |
| 1 | 3 | GTI User Manual |
| 2 | 3 | Polo GTi Performance Tweaks |
| 3 | 4 | Hilux 4x4 Cheat Guide |
| 4 | 4 | Supra TuneUp |
| 5 | 5 | CBR600 Service Manual |
| 6 | 5 | CBR1000RR Service Manual |
基本上,他们应该输出:
汽车 (4)
大众 (2)
丰田 (2)
自行车 (2)
本田 (1)
雅马哈 (0)
目前我可以使用列表视图,但我很难让它计算总数。
查询列出类别:
function insert_get_categories($a)
{
global $config,$conn;
$query = "select * from categories_docs where parent='0' order by name asc";
$results = $conn->execute($query);
$returnthis = $results->getrows();
return $returnthis;
}
渲染 PHP 的 TPL:(使用 Smarty)
{insert name=get_categories assign=listcats}
{section name=o loop=$listcats}
<div class="column {if $smarty.section.o.iteration % 6 == 0}last{/if}"><br>
<h3><a href="{$baseurl}/subcategory.php?id={$listcats[o].CATID}"> {$listcats[o].name|stripslashes}</a></h3>
</div>
{/section}
任何帮助将不胜感激!
提前致谢。
【问题讨论】:
-
请注意,按照惯例,我们使用 NULL 而不是 0 来表示孤儿。