Hi,
I'm having some issues with a while loopIf anyone can help, I'd be over-the-moon.
I have a category table:
id | name
0 | home
1 | contact
and pages table:
id | name | file_name | cat
0 | home page | index.php | 0
1 | get in touch | get-in-touch.php | 1
2 | guestbook | guestbook.php | 1
3 | feedback | feedback.php | 1
Now my idea is to use a while loop to display all the pages in my database like the following:
But I'm a little unsure where to start.HTML Code:<li id="home"> <!-- category name for the element id --> <a href="">home</a> <!-- category name for the anchor text --> <div class="callout" id="hometab"> <!-- category name before tab in id --> <ul> <li><a href="#">home page</a></li><!-- page name for anchor text --> </ul> </div> </li> <li id="contact"> <a href="">contact</a> <div class="callout" id="contacttab"> <ul> <li><a href="#">get in touch</a></li> <li><a href="#">guestbook</a></li> <li><a href="#">feedback</a></li> </ul> </div> </li> .........etc....................
Many thanks for any pointers, reeeeeally appreciate any help with this.
I've been racking my brains for hours now.
P.S.
Probably anything but helpful but I did try the following earlier, but didn't get the right result:
PHP Code:<?
require_once('connect.php');
$sql = "SELECT pages.name, pages.file_name, pages.cat, category.id, category.name FROM pages INNER JOIN category ON category.id = pages.cat";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
if (empty($last) || $last != $row['name']) {
echo '<li id="' . $row['4'] . '">
<a href="/' . $row['4'] . '">' . $row['4'] . '</a>
<a class="tab" href="/' . $row['4'] . '"></a>
<div class="callout" id="' . $row['4'] . 'tab">';
$last = $row['name'];
echo '<ul>';
}
echo '<li>' . $row['1'] . '</li>';
if (empty($last) || $last != $row['name']) {
echo '</ul>
</div>
</li>';
}
}
?>



If anyone can help, I'd be over-the-moon.



Bookmarks