I have one table named group
and i want to get all childrens and parents by using specific id:
Here is my table structure:
CREATE TABLE IF NOT EXISTS `group_tbl` (
`group_id` int(11) NOT NULL AUTO_INCREMENT,
`group_name` varchar(255) NOT NULL,
`parent_id` int(11) NOT NULL,
PRIMARY KEY (`group_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
INSERT INTO `group_tbl` (`group_id`, `group_name`, `parent_id`) VALUES
(1, 'Test', 0),
(2, 'Test1', 1),
(3, 'Test3', 2),
(4, 'Test4', 3),
(5, 'Test5', 3),
(6, 'Test11', 4);
(7, 'Test12', 0),
(8, 'Test34', 8);
if i pass 3,outpur would be
(1, 'Test', 0),
(2, 'Test1', 1),
(3, 'Test3', 2),
(4, 'Test4', 3),
(5, 'Test5', 3)
(6, 'Test11', 4);
How can i get using single query or store procedure or any php function?