I have a table like this
CREATE TABLE IF NOT EXISTS `categories` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(150) NOT NULL,
`parent_id` INT(11) NULL,
`slug` VARCHAR(150) NOT NULL,
PRIMARY KEY (`id`),
)
This is an example of the table as how it is currently:
id name parent_id slug
----------------------------------------------------
1 Books NULL books
2 Anthology 1 anthology
3 Classic 1 classic
4 Drama 1 drama
5 Fable 1 fable
6 Aesop 5 aesop
7 Bidpai 5 bidpai
8 Stephen King 2 stephen-king
9 Magazines NULL magazines
10 Lifestyle 9 lifestyle
11 Wellness 9 wellness
12 Spa 11 spa
Note: i am on an old version of MySQL (5.0) so i cannot use recursive functions unfortunately
I want to select all parents and include them into the search result as well to get a nice overview of all the categories with the correct slugs in my application like this:
id name id_route slug
----------------------------------------------------
1 Books 1 books
2 Anthology 1,2 books/anthology
3 Classic 1,3 books/classic
4 Drama 1,4 books/drama
5 Fable 1,5 books/fable
6 Aesop 1,5,6 books/fable/aesop
7 Bidpai 1,5,7 books/fable/bidpai
8 Stephen King 1,2,8 books/anthology/stephen-king
9 Magazines 9 magazines
10 Lifestyle 9,10 magazines/lifestyle
11 Wellness 9,11 magazines/wellness
12 Spa 9,11,2 magazines/wellness/spa
Is it possible to retrieve a result like this in the first place? Because i am breaking my head around this at the moment. Any help or a push in the right direction would be amazing!