Hello,
im trying to pull together a category and subcategory style setup using join but I cant seem to get the MySQL to work.
looking to do do 2 thing:
1 by example: technology
– computer
---- laptop
------and list what every under this category
- create a breadcrumb based on above results
technology
– computer
---- laptop
$dbArray1 = array(); //db-table query array
Try
{ $STM = $dbhandle->prepare("SELECT
q1.cat_category AS parent,
q2.cat_index ,
q2.cat_category
FROM tbl_categories as q1
LEFT JOIN tbl_categories as q2 ON q2.cat_parent = q1.cat_index
WHERE q2.cat_parent = $catid ");
$STM->execute();
while($row = $STM->fetch(PDO::FETCH_ASSOC))
{ //Built with query in while loop
$dbArray1[$row['parent']][$row['cat_index']] = $row['cat_category'];
}
} catch (PDOException $e) { echo 'Connection failed1: ' . $e->getMessage(); }
cat_index | cat_parent | cat_category
1 0 Business
2 0 Pets
3 0 technology
4 3 computers
5 2 dogs, puppies for sale
6 4 printer
7 4 laptop
8 2 cats, kittens
9 3 tablet
10 2 birds, buy & sell