Hi..im trying to create a menu structure from 2 database tables. Using mysql, i could query a record for the initial loop, and add another loop within in it using <?php do { ?>.
Now that ive mode onto PDO im having an issue, well, i understand that queries must be finished before another can start, so i thought of joining the tables and structuring the output.
The output structure should be:
Start repeat C1
<li>
<ul>
Start repeat C2
<li></li>
End repeat C2
</ul>
<li>
End repeat C1
Although the query i have is correct (i can echo c1 title and underneath echo all the available subtitles from C2) and having a nightmare with the structure...that the final </ul> </li>
are part of the count and are outputted to the number of records from C2, rather than just closing the structure before the end of the C1 loop
The code so far is:
<?php
$sql ="SELECT
n1.cat1id
, n1.c1_tit_it
, n2.c2_tit_it
FROM n_cat1 n1
JOIN n_cat2 n2 ON n1.cat1id = n2.cat1link
ORDER BY c1_tit_it, c2_tit_it";
$res = $pdo->query($sql);
$current = '';
foreach ($res as $row) {
$c1 = str_replace(" ", "-", $row['c1_tit_it']);
$c2 = str_replace(" ", "-", $row['c2_tit_it']);
if ($row['c1_tit_it'] != $current) {
echo '<li class="has-dropdown">
<a href="#">'.$c1.'</a>
<ul>';
$current = $row['c1_tit_it'];
}
echo '<li><a href="#">'.$c2.'</a></li>';
?> </ul> </li><?php // This is the problem area
}
?>
I hope someone is available to help me on this...so near, yet so far at the moment