Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. $result = mysql_query("SELECT categoryID, catname, parentID FROM sxc_faq_categories ORDER BY categoryID ASC");
  2. function faqAGetCategories() {
  3.  
  4. // Get all the categories
  5. $result = mysql_query("SELECT categoryID, catname, parentID FROM sxc_faq_categories ORDER BY categoryID ASC");
  6.  
  7. // Put them into an array
  8. while ($row = mysql_fetch_assoc($result)) {
  9. $cats[] = $row;
  10. }
  11.  
  12. // Declare a counter. Used to keep track of each possibility.
  13. $i = 0;
  14.  
  15. // Dupe the cats array... Needed to emulate the previous query.
  16. $dupe = $cats;
  17. foreach ($cats as $cat) {
  18. // Increase the counter.
  19. $i++;
  20.  
  21. // While looping through the original array with each category, set the current cat ID. Have to dupe this as well.
  22. $cata = $cat['categoryID'];
  23.  
  24. // Now get them down to root.
  25. while ($cata != 0) {
  26. echo "Cata is: $cata ' '";
  27. // This is where the emulated query is. If not emulated, there would be alot of queries.
  28. foreach ($dupe as $dup) {
  29. // If the current category ID is equal to one in the duped array, get the contents of that array (its multidimension)
  30. if ($dup['categoryID'] == $cata) {
  31. $new['categoryID'] = $dup['categoryID'];
  32. $new['catname'] = $dup['catname'];
  33. $new['parentID'] = $dup['parentID'];
  34. }
  35. }
  36.  
  37. // Put that info (catID, catname and parentID) into an array
  38. $breadcrumbs[$i][] = array(
  39. 'catID'=>$new['categoryID'],
  40. 'catname'=>$new['catname'],
  41. 'parentID'=>$new['parentID']
  42. );
  43.  
  44. // Change the $cat to parentID so it will recursively search until the root comes up.
  45. echo "<br />Before cata is: $cata ";
  46. $cata = $new['parentID'];
  47. echo "<br />After cata is: $cata ";
  48. sort($breadcrumbs[$i]);
  49. }
  50. }
  51. }
  52.  
  53. faqAGetCategories();
  54. while($row = mysql_fetch_assoc($result))
  55. {
  56. $real[] = $row;
  57. }
  58. $result = mysql_query("SELECT categoryID, catname, parentID FROM sxc_faq_categories ORDER BY categoryID ASC");
  59.  
  60. echo 'Printr:<br />';
  61. echo '<pre>';
  62. print_r($real);
  63. echo '</pre>';
  64. echo '<br /><br />';
  65. echo 'var dump: <br /><pre>';
  66. var_dump($real);
  67. echo '</pre>';
  68. ?>
  69. *************************output*****************************************************************
  70.  
  71. Cata is: 1 ' '
  72. Before cata is: 1
  73. After cata is: 0 Cata is: 2 ' '
  74. Before cata is: 2
  75. After cata is: 0 Cata is: 3 ' '
  76. Before cata is: 3
  77. After cata is: 1 Cata is: 1 ' '
  78. Before cata is: 1
  79. After cata is: 0 Cata is: 4 ' '
  80. Before cata is: 4
  81. After cata is: 3 Cata is: 3 ' '
  82. Before cata is: 3
  83. After cata is: 1 Cata is: 1 ' '
  84. Before cata is: 1
  85. After cata is: 0 Cata is: 5 ' '
  86. Before cata is: 5
  87. After cata is: 2 Cata is: 2 ' '
  88. Before cata is: 2
  89. After cata is: 0 Cata is: 6 ' '
  90. Before cata is: 6
  91. After cata is: 5 Cata is: 5 ' '
  92. Before cata is: 5
  93. After cata is: 2 Cata is: 2 ' '
  94. Before cata is: 2
  95. After cata is: 0 Cata is: 7 ' '
  96. Before cata is: 7
  97. After cata is: 5 Cata is: 5 ' '
  98. Before cata is: 5
  99. After cata is: 2 Cata is: 2 ' '
  100. Before cata is: 2
  101. After cata is: 0 Printr:
  102.  
  103. Array
  104. (
  105. [0] => Array
  106. (
  107. [categoryID] => 1
  108. [catname] => Cat1
  109. [parentID] => 0
  110. )
  111.  
  112. [1] => Array
  113. (
  114. [categoryID] => 2
  115. [catname] => Cat2
  116. [parentID] => 0
  117. )
  118.  
  119. [2] => Array
  120. (
  121. [categoryID] => 3
  122. [catname] => Cat3
  123. [parentID] => 1
  124. )
  125.  
  126. [3] => Array
  127. (
  128. [categoryID] => 4
  129. [catname] => Cat4
  130. [parentID] => 3
  131. )
  132.  
  133. [4] => Array
  134. (
  135. [categoryID] => 5
  136. [catname] => Cat5
  137. [parentID] => 2
  138. )
  139.  
  140. [5] => Array
  141. (
  142. [categoryID] => 6
  143. [catname] => Cat6
  144. [parentID] => 5
  145. )
  146.  
  147. [6] => Array
  148. (
  149. [categoryID] => 7
  150. [catname] => Cat7
  151. [parentID] => 5
  152. )
  153.  
  154. )
  155.  
  156.  
  157.  
  158. var dump:
  159.  
  160. array(7) {
  161. [0]=>
  162. array(3) {
  163. ["categoryID"]=>
  164. string(1) "1"
  165. ["catname"]=>
  166. string(4) "Cat1"
  167. ["parentID"]=>
  168. string(1) "0"
  169. }
  170. [1]=>
  171. array(3) {
  172. ["categoryID"]=>
  173. string(1) "2"
  174. ["catname"]=>
  175. string(4) "Cat2"
  176. ["parentID"]=>
  177. string(1) "0"
  178. }
  179. [2]=>
  180. array(3) {
  181. ["categoryID"]=>
  182. string(1) "3"
  183. ["catname"]=>
  184. string(4) "Cat3"
  185. ["parentID"]=>
  186. string(1) "1"
  187. }
  188. [3]=>
  189. array(3) {
  190. ["categoryID"]=>
  191. string(1) "4"
  192. ["catname"]=>
  193. string(4) "Cat4"
  194. ["parentID"]=>
  195. string(1) "3"
  196. }
  197. [4]=>
  198. array(3) {
  199. ["categoryID"]=>
  200. string(1) "5"
  201. ["catname"]=>
  202. string(4) "Cat5"
  203. ["parentID"]=>
  204. string(1) "2"
  205. }
  206. [5]=>
  207. array(3) {
  208. ["categoryID"]=>
  209. string(1) "6"
  210. ["catname"]=>
  211. string(4) "Cat6"
  212. ["parentID"]=>
  213. string(1) "5"
  214. }
  215. [6]=>
  216. array(3) {
  217. ["categoryID"]=>
  218. string(1) "7"
  219. ["catname"]=>
  220. string(4) "Cat7"
  221. ["parentID"]=>
  222. string(1) "5"
  223. }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement