数据库错误输出中的类别和子类别

时间:2013-02-07 19:08:02

标签: mysql categories

我有这个查询

SELECT  c1.Id, c1.Name as parent , c2.name as child
              FROM categories c1
                JOIN categories c2 ON c1.id = c2.parentid

请为什么我父母的输出是这样的:

parent1 parent2 parent3 parent1

这是完整的代码:

<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>

只有在子类别的第一个字母是字母&#34; A&#34;

时才会发生这种情况

1 个答案:

答案 0 :(得分:0)

a)什么是momething
b)直接在DB中运行时查询的输出是什么?
c)删除@,以便您能够看到错误 d)正如njk所提到的,你应该使用MySQLi或PDO,不推荐使用mysql_ *函数!