Guest User

Untitled

a guest
Jan 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.71 KB | None | 0 0
  1. <table border="1" width="100%" cellspacing="0" cellpadding="2">
  2. <tr class="dataTableHeadingRow">
  3. <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
  4. <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_WEIGHT; ?>&nbsp;</td>
  5. </tr>
  6.  
  7. <?php
  8. function category_list( $category_parent_id = 0 )
  9. {
  10. // build our category list only once
  11. static $cats;
  12.  
  13. if ( ! is_array( $cats ) )
  14. {
  15. $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';
  16. $res = tep_db_query( $sql );
  17. $cats = array();
  18.  
  19. while ( $cat = tep_db_fetch_array( $res ) )
  20. {
  21. $cats[] = $cat;
  22. }
  23. }
  24.  
  25. // populate a list items array
  26. $list_items = array();
  27.  
  28. foreach ( $cats as $cat )
  29. {
  30. // if not a match, move on
  31. if ( ( int ) $cat['parent_id'] !== ( int ) $category_parent_id )
  32. {
  33. continue;
  34. }
  35.  
  36. // open the list item
  37. $list_items[] = '<tr class="dataTableRow">';
  38. $list_items[] = '<td class="dataTableContent"><li>';
  39.  
  40. // construct the category link
  41.  
  42. $list_items[] = $cat['categories_name'];
  43.  
  44. // recurse into the child list
  45. $list_items[] = category_list( $cat['categories_id'] );
  46.  
  47. // close the list item
  48. $list_items[] = '</li></td>';
  49. $list_items[] = '</tr>';
  50. }
  51.  
  52. // convert to a string
  53. $list_items = implode( '', $list_items );
  54.  
  55. // if empty, no list items!
  56. if ( '' == trim( $list_items ) )
  57. {
  58. return '';
  59. }
  60.  
  61. // ...otherwise, return the list
  62. return '<ul>' . $list_items . '</ul>';
  63. }
  64.  
  65. echo category_list();
  66. ?>
  67. <td class="dataTableContent"></td>
  68. </table>
  69.  
  70. // open the list item
  71. $list_items[] = '<tr class="dataTableRow">';
  72. $list_items[] = '<td class="dataTableContent"><li>';
  73.  
  74. // construct the category link
  75.  
  76. $list_items[] = $cat['categories_name'];
  77.  
  78. // recurse into the child list
  79. $list_items[] = category_list( $cat['categories_id'] );
  80.  
  81. // close the list item
  82. $list_items[] = '</li></td>';
  83. $list_items[] = '</tr>';
  84.  
  85. <table border="1" width="100%" cellspacing="0" cellpadding="2">
  86. <tr class="dataTableHeadingRow">
  87. <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
  88. <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_WEIGHT; ?>&nbsp;</td>
  89. </tr>
  90. <tr class="dataTableRow">
  91. <td class="dataTableContent">
  92. <?php
  93. function category_list( $category_parent_id = 0 )
  94. {
  95. // NOTE THE ADDITIION OF THE PARENT ID:
  96. $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;
  97. $res = tep_db_query( $sql );
  98. $cats = array();
  99.  
  100. while ( $cat = tep_db_fetch_array( $res ) )
  101. {
  102. $cats[] = $cat;
  103. }
  104.  
  105. if (count($cats) == 0)
  106. {
  107. // There are no categories to list
  108. return '';
  109. }
  110.  
  111. // Create a list HTML string
  112. $list = '<ul>';
  113.  
  114. foreach ( $cats as $cat )
  115. {
  116. // open the list item
  117. $list .= '<li>';
  118.  
  119. // construct the category link
  120.  
  121. $list .= $cat['categories_name'];
  122.  
  123. // recurse into the child list
  124. $list .= category_list( $cat['categories_id'] );
  125.  
  126. // close the list item
  127. $list .= '</li>';
  128. }
  129.  
  130. // close and return the list
  131. $list .= '</ul>';
  132. return $list;
  133.  
  134. }
  135.  
  136. echo category_list();
  137. ?>
  138. </td>
  139. <td class="dataTableContent"></td>
  140. </tr>
  141. </table>
  142.  
  143. <table border="1" width="100%" cellspacing="0" cellpadding="2">
  144. <tr class="dataTableHeadingRow">
  145. <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
  146. <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_WEIGHT; ?>&nbsp;</td>
  147. </tr>
  148. <?php
  149. function category_list( $category_parent_id = 0, $level = 0 )
  150. {
  151. // NOTE THE ADDITIION OF THE PARENT ID:
  152. $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;
  153. $res = tep_db_query( $sql );
  154. $cats = array();
  155.  
  156. while ( $cat = tep_db_fetch_array( $res ) )
  157. {
  158. $cats[] = $cat;
  159. }
  160.  
  161. $list = '';
  162. foreach ( $cats as $cat )
  163. {
  164. // start the next row:
  165. $list .= "<tr class="dataTableRow">n";
  166. // The cell for the category needs
  167. $list .= "<td class="dataTableContent">n";
  168.  
  169. // construct the category link. Note we are now enclosing
  170. // this in a div with a left-indent to show the sub level
  171. // this category is at. Adjust the padding-left calculation
  172. // to suit your page
  173. $list .= '<div style="padding-left: ' . (2 * $level) . 'em;">';
  174. $list .= "&bull; {$cat['categories_name']}";
  175. $list .= "</div>n";
  176.  
  177. // close the row
  178. $list .= "</td>n";
  179. $list .= "<td class="dataTableContent"></td>n";
  180. $list .= "</tr>n";
  181.  
  182. // recurse into the child list, incrementing $level
  183. $list .= category_list( $cat['categories_id'], 1+$level );
  184. }
  185.  
  186. // return the list
  187. return $list;
  188.  
  189. }
  190.  
  191. echo category_list();
  192. ?>
  193. </table>
  194.  
  195. <!-- populate the array of data to be displayed -->
  196. <?php $list_items = category_list(); ?>
  197.  
  198. <!-- start the table, display header rows -->
  199. <table border="1" width="100%" cellspacing="0" cellpadding="2">
  200. <tr class="dataTableHeadingRow">
  201. <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
  202. <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_TOTAL_WEIGHT; ?>&nbsp;</td>
  203. </tr>
  204. <tr class="dataTableRow">
  205. <td class="dataTableContent">
  206.  
  207. <ul>
  208. <!-- iterate over data array, create ul for each member -->
  209. <?php
  210. foreach($list_items as $item) {
  211. ?>
  212. <li><?php print $item ?></li>
  213. <?php
  214. }
  215. ?>
  216. </ul>
  217.  
  218. <!-- finish the table -->
  219. </td>
  220. </tr>
  221. </table>
  222.  
  223. <!-- define function which will populate your array -->
  224. <?php
  225. function category_list( $category_parent_id = 0 )
  226. {
  227. /*
  228. this function will look very similar to the one in the
  229. one in the original post but will just return the whole
  230. array instead of printing out one member.
  231. */
  232.  
  233. // populate $items_list...
  234. return $items_list;
  235. }
  236. ?>
  237.  
  238. $list_items[] = '<tr class="dataTableRow">';
  239. $list_items[] = '<td class="dataTableContent"><li>';
  240.  
  241. $list_items[] = "<tr class='dataTableRow'>";
  242. $list_items[] = "<td class='dataTableContent'><li>";
Add Comment
Please, Sign In to add comment