我有这个查询
SELECT c1.Id, c1.Name as parent , c2.name as child
FROM categories c1
JOIN categories c2 ON c1.id = c2.parentid
请为什么我对父母的输出是这样的:
父母1 父母2 父母3 父母1
这是完整的代码:
<div id="categories" class="s_nav">
<ul>
<li id="menu_home"> <a href="/">Home</a> </li>
<?
$query = "SELECT c1.Id, c1.Name as parent , c2.name as child
FROM categories c1
JOIN categories c2 ON c1.id = c2.parentid";
$result = mysql_query($query);
$parent = '';
while ($next = @mysql_fetch_array($result)) {
if ($next['parent'] != $parent) {
if (strlen($parent) > 0) {
echo " </ul></div></li>";
}
echo " <li><a href='#'>" . $next['parent']."</a>";
echo " <div class='s_submenu'><h3>".$next['parent']."</h3>
<ul class='s_list_1 clearfix'>";
}
echo ' <li> <a href="'. $next['child'].'.htm">' . $next['child'] . '</a></li>';
$parent = $next['parent'];
}
echo " </ul>";
echo " </li>";
?>
</ul>
</div>
并且仅当子类别的第一个字母是字母“A”时才会发生这种情况