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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:02:50+00:00 2026-05-17T21:02:50+00:00

I’m working on a CMS system that receives urls like this: /parent1/parent2/child/ Now it’s

  • 0

I’m working on a CMS system that receives urls like this:

/parent1/parent2/child/

Now it’s easy to check only the child but in my opinion you should also check if the parents are correct and in the right order. The problem is that I’m unsure on how to do this.

I’m using mysql. this is how that table would look:

CREATE TABLE IF NOT EXISTS `pages` (
  `id` int(11) NOT NULL auto_increment,
  `parent` int(11) NOT NULL default '0',
  `title` varchar(255) NOT NULL,
  `deleted` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`id`),
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

the parent field keeps other page ID’s that will be used as parent when in the parent field.

  • 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-17T21:02:51+00:00Added an answer on May 17, 2026 at 9:02 pm

    Ok I worked out my own method, Please not I’m using kohana so I’m using the query builder of kohana:

    This piece of code builds the array I want to use.

    public function build_array($parent = 0, $data = null)
    {
        if(!$data)
        {
            $result = db::select('*')
                ->from($this->_table_name)
                ->as_assoc()
            ->execute($this->_db);
    
            foreach($result as $page)
            {
                $data['items'][$page['id']] = $page;
                $data['parents'][$page['parent']][] = $page['id']; 
            }
        }
    
        if (isset($data['parents'][$parent]))
        {
            $array = array();
            foreach ($data['parents'][$parent] as $item)
            {
                $array[$data['items'][$item]['slug']] = array(
                    'id' => $data['items'][$item]['id'],
                    'subitems' => $this->build_array($item, $data)
                );
            }
            return $array;
        }
    }
    

    And this piece of code runs the url trough the array it gets stuck if a parent is wrong:

    public function get_id($page, $parents)
    {    
        $array = $this->build_array();
    
        if(!empty($parents[0]))
        {
            foreach($parents as $parent)
            {
                $array = $array[$parent]['subitems'];
            }
        }
    
        return $array[$page]['id'];
    }
    

    Note: The data you need to send to this function is:

    $page = 'child'; 
    $parent = 'parent1/parent2';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't

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.