我试图在数据库查询上放置一个限制子句,只显示前 4 个结果。
我正在使用的当前代码是
$categories_query = "select c.categories_id, cd.categories_name, c.parent_id
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.categories_id = cd.categories_id
and c.categories_status=1 " .
// "and c.categories_id = ptc.category_id " .
// "and ptc.category_id = cd.categories_id " .
// "and ptc.product_type_id not in " . $this->document_types_list . "
" and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
order by c.parent_id, c.sort_order, cd.categories_name";
$categories = $db->Execute($categories_query);
while (!$categories->EOF) {
$this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0);
$categories->MoveNext();
}
我遇到的问题是我找到了一种通过LIMIT 4
在订单查询之后放置仅限制 4 个结果的方法,它显示了前 4 个父类别,但它也从列表中删除了子类别。
所以我想拿这个
<ul>
<li>Menu One</li>
<li>Menu Two
<ul>
<li>Submenu One</li>
<li>Submenu Two</li>
<li>Submenu Three</li>
</ul>
</li>
<li>Menu Three</li>
<li>Menu Four</li>
<li>Menu Five</li>
<li>ect...</li>
</ul>
看到这个
<ul>
<li>Menu One</li>
<li>Menu Two
<ul>
<li>Submenu One</li>
<li>Submenu Two</li>
<li>Submenu Three</li>
</ul>
</li>
<li>Menu Three</li>
<li>Menu Four</li>
</ul>
并且在查询中放置“LIMIT 4”时,它只显示这个
<ul>
<li>Menu One</li>
<li>Menu Two</li>
<li>Menu Three</li>
<li>Menu Four</li>
</ul>
如何将子类别与父类别保持一致?Aparently 仅调用前 4 个不会调用其下的类别