Trying to generate category and subcategory to display

Hello,
I’m trying to create a small classified system and having little problem generating the data from the database.
i like to be query the database and pull category and there respective categories and display the data like a classified ad layout style.

sample data from the database and the NULL is the leading categories.

	cat_index  cat_parent 	cat_categorytitle
	1 	           NULL	       buy and sell
	2 	           NULL	       services
	3 	           NULL	       pets
	4 	           NULL	       community
	5 	           NULL	       sports
	6 	           NULL	       real estate
	7 	            1                art, collectibles
	8                  1 	              antiques
	9                  1 	              appliances
       10                 5                sports
	11                5                football
	12                5                hockey

the mysql statement


function displayCategory2($dbh)
{	Try
	{	$STM = $dbh->prepare("SELECT t1.cat_categorytitle AS lev1,
									 t2.cat_categorytitle AS lev2,
									 t3.cat_categorytitle AS lev3,
									 t4.cat_categorytitle AS lev4
					FROM tbl_categories AS t1
			   LEFT JOIN tbl_categories AS t2 ON t2.cat_parent = t1.cat_index
			   LEFT JOIN tbl_categories AS t3 ON t3.cat_parent = t2.cat_index
			   LEFT JOIN tbl_categories AS t4 ON t4.cat_parent = t3.cat_index
			       WHERE t1.cat_parent is NULL
				   GROUP BY t1.cat_categorytitle");			
		$STM->execute();
		$mainCategory = $STM->fetchAll(PDO::FETCH_ASSOC);		
	}   catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); }
	return $mainCategory;


any thoughts

Here is a means of doing it that supports an infinite depth selecting all items with a simple query and leaving it up to the application language to build the tree.