-1

I have a category table like this

id  |   parentId    |   category

1   |   0           |   sports  
2   |   1           |   cricket
3   |   2           |   batsman
4   |   0           |   Cinima
5   |   4           |   Bolywood
6   |   5           |   Actor

And an item table like this

id  |   categoryId  |   item

1   |   3           |   Sachin  
2   |   6           |   Amirkhan

I want to select the item and relate it with its parent categories. for eg i want to print a result as

Sachin(batsman-cricket-sports)

Amirkhan(actor-bollywood-cinima)

I have unlimited number of subcategories and can i select all thse in a single query using php and laravel.(i don't likes to use a third relation table for keeping category-subcategory relationship) Is it possible?

Vishal
  • 552
  • 1
  • 6
  • 20
  • Possible duplicate of [What are the Options for Storing Hierarchical Data in a Relational Database?](http://stackoverflow.com/questions/4048151/what-are-the-options-for-storing-hierarchical-data-in-a-relational-database) – vhu Nov 02 '15 at 09:51
  • I haven't read the above article, but I would advise you to change your schema so that it is easier to identify the _groups_ into which each category falls. As it stands now, you're going to need Gordon Linoff to answer your question. – Tim Biegeleisen Nov 02 '15 at 09:53

1 Answers1

1

Check this plugin. This what You are doing is called tree behaviour, or tree model. It is not popular, becouse saving is quick, but read quite slow. Add to composer, require and have a nice day

Janko
  • 202
  • 2
  • 11
  • 1
    Actually i don't likes to use an external plugin.I just wants to code it in ordinary way. – Vishal Nov 04 '15 at 03:11