Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $result = mysql_query("SELECT categoryID, catname, parentID FROM sxc_faq_categories ORDER BY categoryID ASC");
- function faqAGetCategories() {
- // Get all the categories
- $result = mysql_query("SELECT categoryID, catname, parentID FROM sxc_faq_categories ORDER BY categoryID ASC");
- // Put them into an array
- while ($row = mysql_fetch_assoc($result)) {
- $cats[] = $row;
- }
- // Declare a counter. Used to keep track of each possibility.
- $i = 0;
- // Dupe the cats array... Needed to emulate the previous query.
- $dupe = $cats;
- foreach ($cats as $cat) {
- // Increase the counter.
- $i++;
- // While looping through the original array with each category, set the current cat ID. Have to dupe this as well.
- $cata = $cat['categoryID'];
- // Now get them down to root.
- while ($cata != 0) {
- echo "Cata is: $cata ' '";
- // This is where the emulated query is. If not emulated, there would be alot of queries.
- foreach ($dupe as $dup) {
- // If the current category ID is equal to one in the duped array, get the contents of that array (its multidimension)
- if ($dup['categoryID'] == $cata) {
- $new['categoryID'] = $dup['categoryID'];
- $new['catname'] = $dup['catname'];
- $new['parentID'] = $dup['parentID'];
- }
- }
- // Put that info (catID, catname and parentID) into an array
- $breadcrumbs[$i][] = array(
- 'catID'=>$new['categoryID'],
- 'catname'=>$new['catname'],
- 'parentID'=>$new['parentID']
- );
- // Change the $cat to parentID so it will recursively search until the root comes up.
- echo "<br />Before cata is: $cata ";
- $cata = $new['parentID'];
- echo "<br />After cata is: $cata ";
- sort($breadcrumbs[$i]);
- }
- }
- }
- faqAGetCategories();
- while($row = mysql_fetch_assoc($result))
- {
- $real[] = $row;
- }
- $result = mysql_query("SELECT categoryID, catname, parentID FROM sxc_faq_categories ORDER BY categoryID ASC");
- echo 'Printr:<br />';
- echo '<pre>';
- print_r($real);
- echo '</pre>';
- echo '<br /><br />';
- echo 'var dump: <br /><pre>';
- var_dump($real);
- echo '</pre>';
- ?>
- *************************output*****************************************************************
- Cata is: 1 ' '
- Before cata is: 1
- After cata is: 0 Cata is: 2 ' '
- Before cata is: 2
- After cata is: 0 Cata is: 3 ' '
- Before cata is: 3
- After cata is: 1 Cata is: 1 ' '
- Before cata is: 1
- After cata is: 0 Cata is: 4 ' '
- Before cata is: 4
- After cata is: 3 Cata is: 3 ' '
- Before cata is: 3
- After cata is: 1 Cata is: 1 ' '
- Before cata is: 1
- After cata is: 0 Cata is: 5 ' '
- Before cata is: 5
- After cata is: 2 Cata is: 2 ' '
- Before cata is: 2
- After cata is: 0 Cata is: 6 ' '
- Before cata is: 6
- After cata is: 5 Cata is: 5 ' '
- Before cata is: 5
- After cata is: 2 Cata is: 2 ' '
- Before cata is: 2
- After cata is: 0 Cata is: 7 ' '
- Before cata is: 7
- After cata is: 5 Cata is: 5 ' '
- Before cata is: 5
- After cata is: 2 Cata is: 2 ' '
- Before cata is: 2
- After cata is: 0 Printr:
- Array
- (
- [0] => Array
- (
- [categoryID] => 1
- [catname] => Cat1
- [parentID] => 0
- )
- [1] => Array
- (
- [categoryID] => 2
- [catname] => Cat2
- [parentID] => 0
- )
- [2] => Array
- (
- [categoryID] => 3
- [catname] => Cat3
- [parentID] => 1
- )
- [3] => Array
- (
- [categoryID] => 4
- [catname] => Cat4
- [parentID] => 3
- )
- [4] => Array
- (
- [categoryID] => 5
- [catname] => Cat5
- [parentID] => 2
- )
- [5] => Array
- (
- [categoryID] => 6
- [catname] => Cat6
- [parentID] => 5
- )
- [6] => Array
- (
- [categoryID] => 7
- [catname] => Cat7
- [parentID] => 5
- )
- )
- var dump:
- array(7) {
- [0]=>
- array(3) {
- ["categoryID"]=>
- string(1) "1"
- ["catname"]=>
- string(4) "Cat1"
- ["parentID"]=>
- string(1) "0"
- }
- [1]=>
- array(3) {
- ["categoryID"]=>
- string(1) "2"
- ["catname"]=>
- string(4) "Cat2"
- ["parentID"]=>
- string(1) "0"
- }
- [2]=>
- array(3) {
- ["categoryID"]=>
- string(1) "3"
- ["catname"]=>
- string(4) "Cat3"
- ["parentID"]=>
- string(1) "1"
- }
- [3]=>
- array(3) {
- ["categoryID"]=>
- string(1) "4"
- ["catname"]=>
- string(4) "Cat4"
- ["parentID"]=>
- string(1) "3"
- }
- [4]=>
- array(3) {
- ["categoryID"]=>
- string(1) "5"
- ["catname"]=>
- string(4) "Cat5"
- ["parentID"]=>
- string(1) "2"
- }
- [5]=>
- array(3) {
- ["categoryID"]=>
- string(1) "6"
- ["catname"]=>
- string(4) "Cat6"
- ["parentID"]=>
- string(1) "5"
- }
- [6]=>
- array(3) {
- ["categoryID"]=>
- string(1) "7"
- ["catname"]=>
- string(4) "Cat7"
- ["parentID"]=>
- string(1) "5"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement