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

  • SEARCH
  • Home
  • 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 518713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:57:55+00:00 2026-05-13T07:57:55+00:00

I am building a system in which the user can build thre own navigation

  • 0

I am building a system in which the user can build thre own navigation menu from a selection of catergories, the way it works is that is they click on ‘Blog’ they they can get an accordion titled ‘Blog’ and on expanding this they see all the blog titles, however as the moment, my application creates multiple accordions if there are multiple blog entries, so at the moment i have two blog entries and when the user slects ‘Blog’ they get to accordions, where as they should get one with all the titles in

Controller:

public function category($content_id) {
    //$this->output->enable_profiler(TRUE);
    if (intval($this->uri->segments[4])){
        $content_id = $this->uri->segments[4];
    } else {
        $content_id = $this->uri->segments[7];
    }
    $data['content'] = $this->site_model->get_content($content_id);
    $this->load->view("call", $data);
}

Model:

    public function get_content($content_id) {
    $this->db->select('*');
    $this->db->from ('content');
    $this->db->join('categories', 'categories.category_id = content.categories_category_id', 'left');
    $this->db->where ('categories_category_id', $content_id);

    $query = $this->db->get();
    return $query->result_array();

}

View:

    <?php
if(isset($content)) {
//  var_dump($content);
    foreach($content as $row) {
        echo "<h2 class='$row[category_name]'><a href='#'>$row[category_name]</a></h2>";
        echo "<div class='$row[category_name]'><a href='index.php/home/get_content/$row[content_id]' class='contentlink'>$row[content_title]</a></div>";
    }
}
?>

How can I alter my code so for category the user selects only one accordion gets built put all the categories realted content is placed in that accordion?

Hope this makes sense.

  • 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-13T07:57:55+00:00Added an answer on May 13, 2026 at 7:57 am

    If I understand correctly you should move the creation of the header out of your loop:

    <?php
    if(isset($content)) {
        echo "<h2 class='$category_name'><a href='#'>$category_name</a></h2>";
        foreach($content as $row) {
            echo "<div class='$row[category_name]'><a href='index.php/home/get_content/$row[content_id]' class='contentlink'>$row[content_title]</a></div>";
        }
    }
    ?>
    

    If you don’t know the category name you could try something like this:

    <?php
    $first = true;
    if(isset($content)) {
        echo "<h2 class='$category_name'><a href='#'>$category_name</a></h2>";
        foreach($content as $row) {
            if ($first) {
                echo "<h2 class='$row[category_name]'><a href='#'>$row[category_name]</a></h2>";
                $first = false;
            }
            echo "<div class='$row[category_name]'><a href='index.php/home/get_content/$row[content_id]' class='contentlink'>$row[content_title]</a></div>";
        }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a with-source system which I am giving out on the 'net for
I'm building a project that uses the JVCL plugin system, which relies on runtime
I am building a multithreaded system that works like this: While there are entities:
When building a system which needs to respond very consistently and fast, is having
We're currently building a system that abstracts all kinds of technical details about web
I am building a system for distributing packages (.zip archives) created by different organizations.
We are currently thinking of building a cache-system to hold data pulled out of
In a .net system I'm building, there is a need for automated e-mail notifications.
Platform Builder is a tool for building a Windows CE Operating system on your
I'm currently tinkering at an OpenBSD system with a view to building myself a

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.