我有以下标记,它显示了类别和子类别的列表:
<table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr class="dataTableHeadingRow">
<td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
<td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_WEIGHT; ?> </td>
</tr>
<?php
function category_list( $category_parent_id = 0 )
{
$sql = 'select cd.categories_name,c.categories_id, c.parent_id, c.sort_order from ' . TABLE_CATEGORIES . ' c, ' . TABLE_CATEGORIES_DESCRIPTION . ' cd where c.categories_id = cd.categories_id AND c.parent_id='.$category_parent_id;
$res = tep_db_query( $sql );
$cats = array();
while ( $cat = tep_db_fetch_array( $res ) )
{
$cats[] = $cat;
}
if (count($cats) == 0)
{
return '';
}
$list_items = array();
foreach ( $cats as $cat )
{
$list_items[] = '<tr class="dataTableRow"><td class="dataTableContent">';
if($category_parent_id != 0) $list_items[] = ' ';
if($category_parent_id == 0 )$list_items[] = '<b>';
$list_items[] = $cat['categories_name'];
if($category_parent_id == 0) $list_items[] = '</b>';
$list_items[] = '</td><td class="dataTableContent">';
$list_items[] = category_list( $cat['categories_id'] );
$list_items[] = '</td></tr>';
}
$list_items[] = '';
return implode( '', $list_items );
}
echo category_list();
?>
</table>
每个类别都以粗体显示,子类别略微向右缩进显示。我需要展示每个子类别中可用的产品。我尝试将所需的产品字段添加到 sql 查询中,但它没有响应。我需要添加以搜索产品的字段是:products_id, products_name
,这些来自表TABLE_PRODUCTS_DESCRIPTION
,并且为了对其类别进行排序,还有另一个名为 的表TABLE_PRODUCTS_TO_CATEGORIES
,其中包含字段products_id and categories_id
。
我该怎么做呢?