Xtremer360 Posted December 6, 2011 Share Posted December 6, 2011 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 https://forums.phpfreaks.com/topic/252613-my-foreach-issue/ Share on other sites More sharing options...
btherl Posted December 6, 2011 Share Posted December 6, 2011 Using the same variable $query might be an issue. I would try using a different variable name for each query. Link to comment https://forums.phpfreaks.com/topic/252613-my-foreach-issue/#findComment-1295072 Share on other sites More sharing options...
ManiacDan Posted December 6, 2011 Share Posted December 6, 2011 $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 https://forums.phpfreaks.com/topic/252613-my-foreach-issue/#findComment-1295074 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.