我对 php 比较陌生,我正在使用 oscommerce 在报告中创建类别、子类别和子类别中可用产品的列表。我已经设法创建了类别列表,然后是子类别(子类别)。我在尝试在子类别之后列出产品时遇到了死胡同。这是编码的片段:
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();
对于列出产品,我有两个需要使用的表product_to_cat
, 和prod_descrip
,通过使用该product_id
字段连接。为了将其列在正确的父级中,product_to_cat
andcat
表与. 连接category_id
。我将如何在正确的类别中打印正确的产品?