I'm such a clueless nube I'm almost embarrassed to post this,
Be kind, please and laugh with me (while you laugh at me). 🙂
Here goes:
What I'm looking for:
<ul>
<li>Department Name 1
<ul>
<li>Article Title a</li>
<li>Article Title z</li>
<li>Article Title t</li>
</ul>
</li>
<li>
Department Name 2
<ul>
<li>Article Title d</li>
<li>Article Title f<li>
</ul>
</li>
<li>
Department Name 3
<ul>
<li>etc...</li>
</ul>
</li>
</ul>
The query (tested by running in flat table and on command line)
$query = "SELECT owner.deptName,titles.title
FROM titles, owner
WHERE titles.deptName = owner.ownerID
ORDER BY deptName";
Here's the best I can figure with the php:
$rows = mysqli_num_rows($result);
while($row = mysqli_fetch_array($result))
{
$dept = $row[0];
echo "<ul><li>". $dept . "<ul>";
for ($ii = 0 ; $ii <= $rows; $ii++)
{
if ($row[0] == $dept)
{
$row = mysqli_fetch_array($result);
$art = $row[1];
echo "<li>". $art . "</li>";
}
}
echo "</ul></li></ul>";
}
WHAT GOES WRONG:
Here is what the resulting page looks like
Here is what the query results look like with no nested list
It prints the list of titles for the first department leaving off the first title
-
It takes the first title from the next department and adds it to the end of the first department
-
When it hits a department that now (because of the incrementation problem) has no associated titles, all heck breaks loose and it dumps line after line of empty list items and doesn't complete the list of departments.