I have this query
SELECT c1.Id, c1.Name as parent , c2.name as child
FROM categories c1
JOIN categories c2 ON c1.id = c2.parentid
please why my ouput on parent is momething like:
parent1 parent2 parent3 parent1
this is the full code :
<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>
and this happens only if the first letter of a subcategory is the letter “A”
a) what is
momething?b) what’s the output of the query when you run it directly in the DB ?
c) remove the
@so you’ll be able to see errorsd) As njk mentioned, you should use either MySQLi or PDO, mysql_* functions are deprecated!