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 3695286
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:35:59+00:00 2026-05-19T04:35:59+00:00

i have a menu generated dynamically by taking title from database. i have set

  • 0

i have a menu generated dynamically by taking title from database. i have set same table for sub pages by adding a column p_id. and my code looks like this.

private $Section = array();
function _menu($root){

    $this->db->select('id,title,p_id');

    $this->db->Where('p_id',$root);

    $this->db->Where('status','active');

    $this->db->Where('type','page');

    $this->db->order_by('sort');

    $query = $this->db->get('pages');

    foreach ($query->result() as $row)

    {

        $this->Section[] = '<ul>';

            $this->Section[] = '<li>';

            $this->Section[] = anchor('site/page/'.$row->id.'#cont_main',$row->title);

            $this->_menu($row->id);

            $this->Section[] = '</li>';

        $this->Section[] = '</ul>';

    }



    $query->free_result();

    return $this->Section;

}



//get menu tree    

function MenuTree(){

    return $this->_menu(0);

}

in above _menu() if a nav have two or more child then it doesn’t displays because the source populated by it gives extra </ul> and <ul>. the source looks like this

<ul>
<li><a href="#">menu 1</a>
    <ul>
        <li><a>menu 1 sub1</a></li>
    </ul>
    <ul>
        <li><a>menu 1 sub2</a></li>
    </ul>
</li>

while i am assuming to get:

<ul>
<li><a href="#">menu 1</a>
    <ul>
        <li><a>menu 1 sub1</a></li>
        <li><a>menu 1 sub2</a></li>
    </ul>
</li>

edited
i have to add menu according to child element. image comes in all menus which doesn’t have child too due to extra <ul></ul> if i use ul before loop. the source looks like this.

<ul>
<li><a href="#">menu 1</a>
    <ul>
        <li><a>menu 1 sub1</a>
            <ul></ul>
        </li>
        <li><a>menu 1 sub2</a></li>
    </ul>
</li>

any idea would be appreciable.

  • 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-19T04:35:59+00:00Added an answer on May 19, 2026 at 4:35 am

    You need to add your ul outside the foreach loop AND make sure that you already have results!

    if ($query->num_rows() > 0) { // we actually have results, open a UL and loop to add the LIs
        $this->Section[] = '<ul>';
        foreach ($query->result() as $row) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp:menu object which I set up to use a SiteMapDataSource but
I have a side-menu with labels under it define the menu-items and are dynamically
i have this code for a CSS Menu... i got it generated by using
Using NetBeans, I have generated Hibernate mapping files and set of POJOs. I have
I have a dynamically generated variable that contains the currently selected city by the
I have a menu running off of a sitemap which one of the SiteMapNode
I have a menu control inside of an updatepanel. When I hover over a
I have a menu with an animation going on, but I want to disable
I have a menu div that I want to slide down so it's always
I have a menu of product brands that I want to split over 4

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.