Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6853555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:31:35+00:00 2026-05-27T01:31:35+00:00

For some reason my ternary operator assignment isn’t work for the second part of

  • 0

For some reason my ternary operator assignment isn’t work for the second part of my array. Anyone see what I’m doing wrong? Its supposed to just see if there is a value for the permalink field and if there isn’t then insert the 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 not that there should be 3 items inside the Social Array and its not saying there is. I’m wondering if it has something to do with that join. Here’s my output:

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
    )

 )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:31:35+00:00Added an answer on May 27, 2026 at 1:31 am

    You have:

    'linke_url' => (empty($child->permalink)) ? $child->link_url : $child->permalink,
    

    I’ll assume you meant 'link_url' and not 'linke_url', so it looks like you’re trying to do:

    If $child->permalink is empty, set 'link_url' to $child->link_url, but, if $child->permalink isn’t empty, set 'link_url' to $child->permalink.

    I would recommend using the shorthand version of the ternary operator ?: which is the form: $a = $b ?: $c which is the same as if $b evaluates to true, i.e. if $b has any value, $a = $b, otherwise $a = $c. For you:

    'link_url' => $child->permalink ?: $child->link_url
    

    If $child->permalink has a value, that will be used, otherwise, the value of $child->link_url will be used. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason I never see this done. Is there a reason why not?
For some reason, my script isn't writing out the text after I remove the
For some reason my simple jquery bind event isn't working. The funny thing is
for some reason my event data isn't working correctly with jquery fullcalendar when I
For some reason the ImageCache module doesn't work. Drupal just doesn't generate the ImageCache
For some reason this function is doing something weird just in Firefox function fadeOUT_sect(id)
For some reason, I can't update the second label. I tested it by asking
For some reason, when I add the ternary if statement to this bit of
For some reason, pthread_create isn't allowing me to pass a struct as an argument.
for some reason I see url of the following format in error_log (might have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.