Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <table border="1" 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 )
- {
- // build our category list only once
- static $cats;
- if ( ! is_array( $cats ) )
- {
- $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';
- $res = tep_db_query( $sql );
- $cats = array();
- while ( $cat = tep_db_fetch_array( $res ) )
- {
- $cats[] = $cat;
- }
- }
- // populate a list items array
- $list_items = array();
- foreach ( $cats as $cat )
- {
- // if not a match, move on
- if ( ( int ) $cat['parent_id'] !== ( int ) $category_parent_id )
- {
- continue;
- }
- // open the list item
- $list_items[] = '<tr class="dataTableRow">';
- $list_items[] = '<td class="dataTableContent"><li>';
- // construct the category link
- $list_items[] = $cat['categories_name'];
- // recurse into the child list
- $list_items[] = category_list( $cat['categories_id'] );
- // close the list item
- $list_items[] = '</li></td>';
- $list_items[] = '</tr>';
- }
- // convert to a string
- $list_items = implode( '', $list_items );
- // if empty, no list items!
- if ( '' == trim( $list_items ) )
- {
- return '';
- }
- // ...otherwise, return the list
- return '<ul>' . $list_items . '</ul>';
- }
- echo category_list();
- ?>
- <td class="dataTableContent"></td>
- </table>
- // open the list item
- $list_items[] = '<tr class="dataTableRow">';
- $list_items[] = '<td class="dataTableContent"><li>';
- // construct the category link
- $list_items[] = $cat['categories_name'];
- // recurse into the child list
- $list_items[] = category_list( $cat['categories_id'] );
- // close the list item
- $list_items[] = '</li></td>';
- $list_items[] = '</tr>';
- <table border="1" 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>
- <tr class="dataTableRow">
- <td class="dataTableContent">
- <?php
- function category_list( $category_parent_id = 0 )
- {
- // NOTE THE ADDITIION OF THE PARENT ID:
- $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)
- {
- // There are no categories to list
- return '';
- }
- // Create a list HTML string
- $list = '<ul>';
- foreach ( $cats as $cat )
- {
- // open the list item
- $list .= '<li>';
- // construct the category link
- $list .= $cat['categories_name'];
- // recurse into the child list
- $list .= category_list( $cat['categories_id'] );
- // close the list item
- $list .= '</li>';
- }
- // close and return the list
- $list .= '</ul>';
- return $list;
- }
- echo category_list();
- ?>
- </td>
- <td class="dataTableContent"></td>
- </tr>
- </table>
- <table border="1" 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, $level = 0 )
- {
- // NOTE THE ADDITIION OF THE PARENT ID:
- $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;
- }
- $list = '';
- foreach ( $cats as $cat )
- {
- // start the next row:
- $list .= "<tr class="dataTableRow">n";
- // The cell for the category needs
- $list .= "<td class="dataTableContent">n";
- // construct the category link. Note we are now enclosing
- // this in a div with a left-indent to show the sub level
- // this category is at. Adjust the padding-left calculation
- // to suit your page
- $list .= '<div style="padding-left: ' . (2 * $level) . 'em;">';
- $list .= "• {$cat['categories_name']}";
- $list .= "</div>n";
- // close the row
- $list .= "</td>n";
- $list .= "<td class="dataTableContent"></td>n";
- $list .= "</tr>n";
- // recurse into the child list, incrementing $level
- $list .= category_list( $cat['categories_id'], 1+$level );
- }
- // return the list
- return $list;
- }
- echo category_list();
- ?>
- </table>
- <!-- populate the array of data to be displayed -->
- <?php $list_items = category_list(); ?>
- <!-- start the table, display header rows -->
- <table border="1" 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>
- <tr class="dataTableRow">
- <td class="dataTableContent">
- <ul>
- <!-- iterate over data array, create ul for each member -->
- <?php
- foreach($list_items as $item) {
- ?>
- <li><?php print $item ?></li>
- <?php
- }
- ?>
- </ul>
- <!-- finish the table -->
- </td>
- </tr>
- </table>
- <!-- define function which will populate your array -->
- <?php
- function category_list( $category_parent_id = 0 )
- {
- /*
- this function will look very similar to the one in the
- one in the original post but will just return the whole
- array instead of printing out one member.
- */
- // populate $items_list...
- return $items_list;
- }
- ?>
- $list_items[] = '<tr class="dataTableRow">';
- $list_items[] = '<td class="dataTableContent"><li>';
- $list_items[] = "<tr class='dataTableRow'>";
- $list_items[] = "<td class='dataTableContent'><li>";
Add Comment
Please, Sign In to add comment