For some reason, my triple statement assignment does not work for the second part of my array. Does anyone see what I'm doing wrong? It should just see if there is a value for the permalink field, and if not, then insert link_url
into the array.
function getSiteMap() { $this->db->select('site_menu_structures_links.id, site_menu_structures_links.link_name'); $this->db->from('site_menu_structures_links'); $this->db->where('site_menu_structures_links.status_id', 1); $this->db->where('site_menu_structures_links.is_category', 'Yes'); $this->db->order_by('site_menu_structures_links.sort_order'); $catQuery = $this->db->get(); if ($catQuery->num_rows()) { foreach ($catQuery->result() as $cats) { // Set the Main Category into the array $testArray[$cats->id] = array( 'id' => $cats->id, 'name' =>$cats->link_name ); $this->db->select('site_content_pages.permalink, site_menu_structures_links_children.id, site_menu_structures_links_children.link_url, site_menu_structures_links_children.link_name'); $this->db->from('site_menu_structures_links_children'); $this->db->join('site_content_pages', 'site_content_pages.id = site_menu_structures_links_children.site_content_pages_id'); $this->db->where('site_menu_structures_links_id', $cats->id); $this->db->where('site_menu_structures_links_children.status_id', 1); $this->db->order_by('site_menu_structures_links_children.sort_order'); $childrenQuery = $this->db->get(); if ($childrenQuery->num_rows()) { foreach ($childrenQuery->result() as $child) { $testArray[$cats->id]['children'][$child->id] = array( 'linke_url' => (empty($child->permalink)) ? $child->link_url : $child->permalink, 'link_name' => $child->link_name, ); } } } } return $testArray; }
EDIT:
Also, there should not be 3 elements inside Social Array and not say what is. I am wondering if this is related to this connection. Here is my conclusion:
Array ( [2] => Array ( [id] => 2 [name] => Roster [children] => Array ( [1] => Array ( [linke_url] => [link_name] => Superstars ) [2] => Array ( [linke_url] => [link_name] => Champions and Contenders ) [3] => Array ( [linke_url] => [link_name] => Title History ) ) ) [3] => Array ( [id] => 3 [name] => Events [children] => Array ( [4] => Array ( [linke_url] => [link_name] => Preview Next Event ) [5] => Array ( [linke_url] => [link_name] => Latest Event Results ) [6] => Array ( [linke_url] => [link_name] => Event Archives ) [7] => Array ( [linke_url] => [link_name] => Schedule An Event ) ) ) [4] => Array ( [id] => 4 [name] => Media [children] => Array ( [8] => Array ( [linke_url] => [link_name] => Photo Gallery ) ) ) [5] => Array ( [id] => 5 [name] => Social ) )
source share