query($sql); while($row = $result->fetch_assoc()) { $cat_id = $row['id']; $sql11 = "SELECT * FROM sub_category where cat_id=$cat_id ORDER BY name ASC"; $result111 = $conn->query($sql11); echo ' '; if ($result111->num_rows > 0) { // output data of each row while($row7 = $result111->fetch_assoc()) { ?>