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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:56:04+00:00 2026-05-30T19:56:04+00:00

I have a table with three columns: id , ref and catName . Every

  • 0

I have a table with three columns: id, ref and catName. Every row contains a category which can be a sub category; if so than the ref column references to the id of the main category. Off course this method makes sure you can create numerous sub categories.

Now I want to make a url for every category containing of the catName‘s of all its parents.

private function getCatUrl($cat, $ur = array()){
       $sql = "SELECT * FROM shop_cat WHERE id = :id LIMIT 1";
       $st = $this->db->prepare($sql);
       $st->bindParam('id', $cat, PDO::PARAM_INT);
       $st->execute();

       $rij = $st->Fetch();
       $ur[] = urlencode($rij['naam']);

       if($rij['ref'] == 0){
           //Done, I've reached the top parent;
           return implode('/',$ur);

       }else{
           //there is a parent/reference above this level
           //getting there
           $this->getCatUrl($rij['ref'], $ur);

       }

   }

Somehow this only produces a $ur for the top parent and not for the childs.
What am I doing wrong?

Sample of the database:

id  ref catName
1   0   GroundFloor
4   1   Portal
5   1   Stairs

2   0   FirstFloor
6   2   DiningArea
12  6   Chair
7   2   Toilet   
9   2   SittingRoom
10  9   Couch
11  9   Dresser

3   0   Roof
8   3   LoungeChair
  • 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-30T19:56:05+00:00Added an answer on May 30, 2026 at 7:56 pm

    You are doing it wrong.

    I would recommend for you to look into Closure Tables [1] [2] [3], and also read the SQL Antipatterns book ( it covers the trees in second chapter).

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

Sidebar

Related Questions

I have a logging table which has three columns. One column is a unique
I have a table with three columns; the first column contains IDs and the
I have a table in SQL Server 2005 which has three columns: id (int),
I have an HTML table with three columns. In the right most column, I
We have a table which has three columns in it: Customer_name, Age_range, Number_of_people. 1
I have a table with three rows and three columns. How can I combine
I have table called emp . The table contains three columns empid , ename
I have a table with three columns and I have fetch a column whose
I have a table with three columns: user varchar, status varchar , rep int
I'm using SQL Server 2008 and I have a table with three columns: Length

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.