SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Feb 2009
    Posts
    994
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie: Help on generating html ul

    I'm not getting the logic, can anyone help me out? With this code:
    PHP Code:
    echo '<ul class="subCategorias">';
        
            foreach (
    $arrMenu as $subcategorias)
        {
           
          echo 
    '<li>';
          echo 
    anchorbase_url() . 'c_categoria/seccao/' $subcategorias[$strParentIdKey] . '/' $subcategorias[$strIdKey] . '/',$subcategorias[$strNameKey]),$strNL;
          echo 
    '</li>';
            
           
           if(!empty(
    $subcategorias[$strChildKey])) 
              {
            if (isset(
    $arraySegmento[4]) and $arraySegmento[4]==6)
            {
                echo 
    '<ul class="subSubCategorias">';
        
                  foreach (
    $subcategorias[$strChildKey] as $subsubcategorias)
                  {
                          
                    echo 
    '<li>'
                    echo 
    anchorbase_url() . 'c_categoria/seccao/1/' $subsubcategorias[$strParentIdKey] . '/' $subsubcategorias[$strIdKey] . '/',$subsubcategorias[$strNameKey]),$strNL;
                    echo 
    '</li>';
                  }
                    
                    echo 
    '</ul>';
            }
                       
        }
            
                 

    I'm able to generate something like this:
    HTML Code:
    <ul>
     <li>cat-1</li>
     <li>cat-2</li>
     <li>cat-3</li>
     <ul>
      <li>subcat-1</li>
      <li>subcat-2</li>
      <li>subcat-3</li>
     </ul>
    </ul>
    But I would like to have two UL siblings instead:
    HTML Code:
    <ul>
     <li>cat-1</li>
     <li>cat-2</li>
     <li>cat-3</li>
    </ul>
    <ul>
     <li>subcat-1</li>
     <li>subcat-2</li>
     <li>subcat-3</li>
    </ul>
    So that I can properly place them side by side using css. Can I have your help please?


    Regards,
    Márcio

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just put one foreach loop after another, not inside
    But it looks kinda unusual, and your first variant makes more sense

  3. #3
    SitePoint Guru
    Join Date
    Feb 2009
    Posts
    994
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, thanks for your reply,

    What first variant are you referring to?

    [update]

    If you are referring to the first <html> snipped code posted, then I must say I agree.

    But, given that structure, can we use css to put both ul elements side by side, at the same height? Something like:

    item1 subitem1
    item2 subitem2
    item3 subitem3

    ?

    [/update]

    Regards,
    M&#225;rcio

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all we need more detailed example.
    Which subcategory belongs to which category?
    From first snippet it looks that all subs belongs to cat-3.

  5. #5
    SitePoint Guru
    Join Date
    Feb 2009
    Posts
    994
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The categories and subcategories are dynamic, hence, I can never tell where/ /or/if each category will have subcategories inside. I believe.

    My question is more css related the php related. I will post my question on the css side of things.

    Thanks for your reply on this,
    Márcio

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You may want to check out the following thread, where I asked a similar question a few days ago - http://www.sitepoint.com/forums/showthread.php?t=648427


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •