Jump to content

My foreach issue


Xtremer360

Recommended Posts

I'm trying to figure out why its only showing the last child_links in the roster, events, and social objects. I've included the site that has the print_r of the array function. Any help would be appreciated.

 

http://kansasoutlawwrestling.com/

 

function getSubMenuPages()
    {
        $this->db->select('site_menu_structures.id');
        $this->db->from('site_menu_structures');
        $this->db->where('site_menu_structures.short_name', 'mainnav'); 
        $query = $this->db->get(); 
        $menu_id = $query->row()->id; 
        
        $this->db->select('site_menu_structures_links.id, site_menu_structures_links.short_name, site_menu_structures_links.is_category');
        $this->db->from('site_menu_structures_links');
        $this->db->where('site_menu_structures_links.menu_structure_id', $menu_id); 
        $query = $this->db->get();
        
        if ($query->num_rows() > 0) 
        {
            $linksArray = $query->result();
            foreach ($linksArray as $key => $link)
            {
                if ($link->is_category == 'Yes')
                {
                    $this->db->select('site_menu_structures_links_children.link_name, site_menu_structures_links_children.site_content_pages_id, site_menu_structures_links_children.link_url');
                    $this->db->from('site_menu_structures_links_children');
                    $this->db->where('site_menu_structures_links_children.site_menu_structures_links_id', $link->id); 
                    $query = $this->db->get();
                    if ($query->num_rows() > 0) 
                    {
                        foreach ($query->result() as $row)
                        {
                            $site_content_page_id = $row->site_content_pages_id;
                            $linksArray[$key]->child_links = array();
                            if ($site_content_page_id != 0)
                            {
                                $this->db->select('site_content_pages.content_page_name, site_content_pages.permalink');
                                $this->db->from('site_content_pages');
                                $this->db->where('site_content_pages.id', $site_content_page_id); 
                                $query = $this->db->get();
                                if ($query->num_rows() > 0)
                                {
                                    $row = $query->row(); 
                                    $linksArray[$key]->child_links = array(
                                                                    'link_name'	 => $row->content_page_name,
                                                                    'link_url' => $row->permalink
                                                                 );
                                }
                            }
                            else
                            {
                                $linksArray[$key]->child_links = array(
                                                                    'link_name'	 => $row->link_name,
                                                                    'link_url' => $row->link_url
                                                                 );
                            }
                        }
                    }
                }
            }
        }
        
        return $linksArray;
        
    }

Link to comment
Share on other sites

$linksArray[$key]->child_links = $whatever;

 

That line makes $linksArray[$key]->child_links into $whatever.  It does NOT append $whatever to the array of $linksArray[$key]->child_links.  You want:

 

$linksArray[$key]->child_links[] = $whatever;

 

-Dan

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.