0

我正在使用 osCommerce 创建一个报告页面来显示每天销售的农产品总量。这是迄今为止我用来显示类别和子类别的标记:

<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; ?>&nbsp;</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[] = '&nbsp;&nbsp;&nbsp;';
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>

我想在子类别之后显示的是每个产品中的产品,这意味着使用TABLE_PRODUCTS_TO_CATEGORIES表格。我有以下代码用于计算产品$query = 'SELECT COUNT(*) FROM '.TABLE_PRODUCTS_TO_CATEGORIES.' WHEREcategories_id` = "'.$cat['categories_id'].'"';。

我将把它放在我的标记中的哪里,我将如何展示产品?

4

2 回答 2

0

为什么不使用您正在使用的同一查询中JOIN的表,如下所示:TABLE_PRODUCTS_TO_CATEGORIES

select 
  cd.categories_name,
  c.categories_id, 
  c.parent_id, 
  c.sort_order,
  p.* -- You can here select the products details you want to select.
from TABLE_CATEGORIES  c
INNER JOIN TABLE_CATEGORIES_DESCRIPTION cd ON c.categories_id = cd.categories_id 
INNER JOIN TABLE_PRODUCTS_TO_CATEGORIES p  ON p.categories_id = c.categories_id 
WHERE c.parent_id = '.$category_parent_id
于 2012-12-04T12:27:29.730 回答
0

这是获取产品的想法,在您检查类别的地方,您还会获得 CATEGORIES_ID

只需在它之后进行另一个查询并调用相同的过程

于 2012-12-04T13:21:06.470 回答