Add </ul> to last of sub cats

i have the folling code

<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_categories.php 4162 2006-08-17 03:55:02Z ajeh $
 */


  $content = "";


  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . '<ul id="bav">' . "\
";
  for ($i=0;$i<sizeof($box_categories_array);$i++) {
    switch(true) {
// to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
// uncomment the select below and set the cPath=3 to the cPath= your_categories_id
// many variations of this can be done
//      case ($box_categories_array[$i]['path'] == 'cPath=3'):
//        $new_style = 'category-holiday';
//        break;
      case ($box_categories_array[$i]['top'] == 'true'):
        $new_style = 'category-top';
        break;

      case ($box_categories_array[$i]['has_sub_cat']):
        $new_style = 'category-subs';
        break;
      default:

        $new_style = 'category-products';

      }
     if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
        // skip if this is for the document box (==3)
      } else {


      $content .= '<li>' . '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';

      if ($box_categories_array[$i]['current']) {

        if ($box_categories_array[$i]['has_sub_cat']) {





          $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';

        } else {


          $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>' . '</a>';

        }
      } else {

        $content .= $box_categories_array[$i]['name'];
 $content .= '</a>';
 $content .= '</li>';


      }

      if ($box_categories_array[$i]['has_sub_cat']) {
 $content .= '</a>';

        $content .= '<ul class="child">' ;


$content .= CATEGORIES_SEPARATOR;

      }


      if (SHOW_COUNTS == 'true') {

        if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
          $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
        }
      }

      $content .=  "\
";
    }
  }
        $content .= '</ul>';
        $content .= '</li>';



  if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true' or SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
// display a separator between categories and links
    if (SHOW_CATEGORIES_SEPARATOR_LINK == '1') {
      $content .= '<hr id="catBoxDivider" />' . "\
";
    }
    if (SHOW_CATEGORIES_BOX_SPECIALS == 'true') {
      $show_this = $db->Execute("select s.products_id from " . TABLE_SPECIALS . " s where s.status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_SPECIALS) . '">' . CATEGORIES_BOX_HEADING_SPECIALS . '</a>' . '<br />' . "\
";
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') {
      // display limits
//      $display_limit = zen_get_products_new_timelimit();
      $display_limit = zen_get_new_date_range();

      $show_this = $db->Execute("select p.products_id
                                 from " . TABLE_PRODUCTS . " p
                                 where p.products_status = 1 " . $display_limit . " limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_NEW) . '">' . CATEGORIES_BOX_HEADING_WHATS_NEW . '</a>' . '<br />' . "\
";
      }
    }
    if (SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true') {
      $show_this = $db->Execute("select products_id from " . TABLE_FEATURED . " where status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' . CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS . '</a>' . '<br />' . "\
";
      }
    }
    if (SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
      $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_ALL) . '">' . CATEGORIES_BOX_HEADING_PRODUCTS_ALL . '</a>' . "\
";
    }
  }
  $content .= '</ul>';
  $content .= '</div>';

?>




outputing the folling html




<div id="Content" class="sideBoxContent"><ul id="bav">
<li><a class="category-top" href="http://www.shopbabby.com/shirts">SHIRTS</a></li>
<li><a class="category-top" href="http://www.shopbabby.com/jackets"><span class="category-subs-parent">JACKETS</span></a><ul class="child">
<li><a class="category-products" href="http://www.shopbabby.com/dvd-movies/action">Action</a></li>
<li><a class="category-products" href="http://www.shopbabby.com/dvd-movies/cartoons">Cartoons</a></li>
<li><a class="category-products" href="http://www.shopbabby.com/dvd-movies/comedy">Comedy</a></li>
<li><a class="category-top" href="http://www.shopbabby.com/pants">PANTS</a></li>
<li><a class="category-top" href="http://www.shopbabby.com/big-linked">Big Linked</a></li>
[COLOR="#FF0000"]</ul></li>[/COLOR]<hr id="catBoxDivider" />
<a class="category-links" href="http://www.shopbabby.com/index.php?main_page=specials">Specials </a><br />
<a class="category-links" href="http://www.shopbabby.com/index.php?main_page=products_new">New Products </a><br />
<a class="category-links" href="http://www.shopbabby.com/index.php?main_page=featured_products">Featured Products </a><br />
<a class="category-links" href="http://www.shopbabby.com/index.php?main_page=products_all">All Products </a>
</ul></div>

i have been trying to get the </ul></li> to immediately follow the </li> of the last “category-product”
how what i add this ?

I don’t have the final answer for your question, I just wanted to point out that this is a really bad way to construct html.

First, get all of your db queries out of the html. You need to get all the data you need upfront in an object / array / hash.
Then make a HTML template free of all logic and direct replacements of values into the template with simple loops.

It’s actually valid HTML5 to lose the closing </li> tags altogether if that helps, so you only need to know when to output the opening and closing ul’s and the opening li’s.


<ul>
<li>blah
<li>blah
</ul>