I cant figure out the right query and all the existing answers are related to Wordpress and I'm not on wordpress, I'm building it from scratch. I've got this table
I want to get all parent ID's. If product is in category "Yellow", i want to get all the parent IDs from Yellow category, so from query "Yellow" would be 70, 68, 66, 0.
So Im spinning around with all possible joins and best result is just current category (or all of them..)
$sql2 = "SELECT c1.ID, c1.si, c2.si, c2.ID as parent_id
FROM v_menu c1
LEFT JOIN v_menu c2
on (c2.parent = c1.ID)
WHERE (c1.ID = :c1)";
$st2 = $this->db->prepare($sql2);
$st2->execute(array(':c1' => $row['MID'])); // $row['MID'] => product category
$res2 = $st2->fetchAll();
This returns only category which matches product category.
Any hint, link, solution... would be in much help.