Category Hierarchy (PHP/MySQL)
When using an adjacency list model, you can generate the structure in one pass. Taken from One Pass Parent-Child Array Structure (Sep 2007; by Nate Weiner): $refs = array(); $list = array(); $sql = “SELECT item_id, parent_id, name FROM items ORDER BY name”; /** @var $pdo \PDO */ $result = $pdo->query($sql); foreach ($result as $row) … Read more