calling an array from one function to another

  • northstjarna
  • Beginner
  • Beginner
  • northstjarna
  • Posts: 58
  • Loc: Chertsey, UK

Post 3+ Months Ago

Hi there got an issue where my array wont be passed from one function to another...

Here is the code....

Code: [ Select ]
/* get breadcrumb function */
function getbreadcrumb($arraycount,$parentmenuid){
    
    /* get the current level menu */
    global $database_eggbox, $eggbox, $urlmenu_id;
    $query_last_breadcrumb = "select * from menu where menu_id = $parentmenuid order by menu_display_order";
    $last_breadcrumb = mysql_query($query_last_breadcrumb, $eggbox) or die(mysql_error());
    $row_last_breadcrumb = mysql_fetch_assoc($last_breadcrumb);
    $totalRows_last_breadcrumb = mysql_num_rows($last_breadcrumb);
    
    $array_menu[$arraycount][0] = $row_last_breadcrumb['menu_id'];
    $array_menu[$arraycount][1] = $row_last_breadcrumb['page_id'];
    $array_menu[$arraycount][2] = $row_last_breadcrumb['menu_text'];
    $array_menu[$arraycount][3] = $row_last_breadcrumb['menu_parent_menu_id'];
    
    if($array_menu[$arraycount][0] != "") {
        getbreadcrumb($arraycount+1,$array_menu[$arraycount][3]);
    } else {
        
        if($array_menu[$arraycount][2] != "home") {
            /// going to output the first crumb as home
        } else {
            /// else >>
        }
    }
    
    echo $array_menu[$arraycount][2] . " | ";
    
} // end function
  1. /* get breadcrumb function */
  2. function getbreadcrumb($arraycount,$parentmenuid){
  3.     
  4.     /* get the current level menu */
  5.     global $database_eggbox, $eggbox, $urlmenu_id;
  6.     $query_last_breadcrumb = "select * from menu where menu_id = $parentmenuid order by menu_display_order";
  7.     $last_breadcrumb = mysql_query($query_last_breadcrumb, $eggbox) or die(mysql_error());
  8.     $row_last_breadcrumb = mysql_fetch_assoc($last_breadcrumb);
  9.     $totalRows_last_breadcrumb = mysql_num_rows($last_breadcrumb);
  10.     
  11.     $array_menu[$arraycount][0] = $row_last_breadcrumb['menu_id'];
  12.     $array_menu[$arraycount][1] = $row_last_breadcrumb['page_id'];
  13.     $array_menu[$arraycount][2] = $row_last_breadcrumb['menu_text'];
  14.     $array_menu[$arraycount][3] = $row_last_breadcrumb['menu_parent_menu_id'];
  15.     
  16.     if($array_menu[$arraycount][0] != "") {
  17.         getbreadcrumb($arraycount+1,$array_menu[$arraycount][3]);
  18.     } else {
  19.         
  20.         if($array_menu[$arraycount][2] != "home") {
  21.             /// going to output the first crumb as home
  22.         } else {
  23.             /// else >>
  24.         }
  25.     }
  26.     
  27.     echo $array_menu[$arraycount][2] . " | ";
  28.     
  29. } // end function


Now when I use the global function to get the array it wont have it...

Code: [ Select ]
/* get menu functions */
function getmenu($menu_level){
        
    /* get the top most level menu */
    global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;
    $query_top_menu = "select * from menu where menu_parent_menu_id = 0 order by menu_display_order";
    $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
    $row_top_menu = mysql_fetch_assoc($top_menu);
    $totalRows_top_menu = mysql_num_rows($top_menu);
    
    if ($menu_level <> 0) {
        echo $array_menu;

......
  1. /* get menu functions */
  2. function getmenu($menu_level){
  3.         
  4.     /* get the top most level menu */
  5.     global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;
  6.     $query_top_menu = "select * from menu where menu_parent_menu_id = 0 order by menu_display_order";
  7.     $top_menu = mysql_query($query_top_menu, $eggbox) or die(mysql_error());
  8.     $row_top_menu = mysql_fetch_assoc($top_menu);
  9.     $totalRows_top_menu = mysql_num_rows($top_menu);
  10.     
  11.     if ($menu_level <> 0) {
  12.         echo $array_menu;
  13. ......


It worked for some functions but not this one... Can anybody help explain what I am doing wrong here?
Thanks
Andi
  • northstjarna
  • Beginner
  • Beginner
  • northstjarna
  • Posts: 58
  • Loc: Chertsey, UK

Post 3+ Months Ago

Its ok figured it out. I had to also declare the array in the global function of the first function...

Code: [ Select ]
/* /* get breadcrumb function */
function getbreadcrumb($arraycount,$parentmenuid){
    
    /* get the current level menu */
    global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;
  1. /* /* get breadcrumb function */
  2. function getbreadcrumb($arraycount,$parentmenuid){
  3.     
  4.     /* get the current level menu */
  5.     global $database_eggbox, $eggbox, $urlmenu_id, $array_menu;

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 50 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.