I\'ve done this before in long complicated statements but I\'m trying to clean up some code.
I have the following table structures
parent_categories
$qry = $conn->prepare('
SELECT a.pid, a.parent_name, b.category_name
FROM parent_categories a
JOIN child_categories b ON a.pid = b.lpid
ORDER BY a.pid
');
if ($qry->execute()) {
echo '';
$row = $qry->fetch();
while ($row) {
$current_pid = $row['pid'];
echo '- ', htmlentities($row['parent_name']), '
';
do {
echo '- ', htmlentities($row['category_name']), '
';
} while ($row = $qry->fetch() and $row['pid'] == $current_pid);
echo '
';
}
echo '
';
}