Page 2 of 2

Posted: Tue Aug 22, 2006 4:47 am
by nmb
hi again.. yes that resolved the problem with the <ul></ul> tags.. mas the code still wrong..

the is the returned code:

Code: Select all

<ul> 
  <li>Cat 1</li> 
  <ul> 
    <li>Cat 1-1</li> 
    <li>Cat 1-2</li> 
    <li>Cat 1-3</li> 
    <ul> 
      <li>Cat 1-3-1</li> 
      <li>Cat 1-3-2</li> 
      <li>Cat 1-3-3</li> 
      <ul> 
        <li>Cat 1-3-3-1</li> 
      </ul> 
      <li>Cat 1-3-4</li> 
    </ul> 
    <li>Cat 1-4</li> 
  </ul> 
  <li>Cat 2</li> 
  <ul> 
    <li>Cat 2-1</li> 
    <li>Cat 2-2</li> 
    <li>Cat 2-3</li> 
  </ul> 
  <li>Cat 3</li> 
  <li>Cat 4</li> 
</ul>

the problem is the script close <li>'s tag before open the sub level <ul>'s.

the correct code is like this one:

Code: Select all

<ul> 
 <li>Cat 1 
  <ul> 
   <li>Cat 1-1</li> 
   <li>Cat 1-2</li> 
   <li>Cat 1-3 
    <ul> 
     <li>Cat 1-3-1</li> 
     <li>Cat 1-3-2</li> 
     <li>Cat 1-3-3 
      <ul> 
       <li>Cat 1-3-3-1</li> 
      </ul> 
     </li> 
     <li>Cat 1-3-4</li> 
    </ul> 
   </li> 
   <li>Cat 1-4</li> 
  </ul> 
 </li> 
 <li>Cat 2 
  <ul> 
   <li>Cat 2-1</li> 
   <li>Cat 2-2</li> 
   <li>Cat 2-3</li> 
  </ul> 
 </li> 
 <li>Cat 3</li> 
 <li>Cat 4</li> 
</ul>
this is the last problem.. i hope :p

Posted: Tue Aug 22, 2006 5:24 am
by onion2k
The solution to this is pretty obvious. You're just trying to get someone to write this code for you without putting in any effort of your own whatsoever. As you just want someone to write this for you I'm moving this thread to Volunteer Work because that's clearly a more appropriate place for it.

If you followup with an actual problem with your code, or a question about how this works so you can solve it yourself, then I'll move it back to the PHP Code folder.

Posted: Tue Aug 22, 2006 5:27 am
by nmb
ok.. the problem is that i don't know to do it..
i don't know how to work with recursion..

..i was only trying to get help on this.. if you think that ok.. no prob. tnks

Posted: Tue Aug 22, 2006 6:32 am
by nmb
ok.. i have the code i need.

Code: Select all

function getTree($id_catsup=0,$level=0) {
  $html = "";
  $sql = "select * from categorias where id_catsup = '".$id_catsup."' order by id";
  $categoryresult = mysql_query($sql);
  if (mysql_num_rows($categoryresult) > 0) {
   $html .= "<ul>";
   while ($record = mysql_fetch_object($categoryresult)) {
    $html .= "<li>".$record->categoria_nome_pt;
    $html .= getTree($record->id,$level+1);
    $html .= "</li>";
   }
   $html .= "</ul>";
  }
  return $html;
 }
 $showcat = getTree(0);
thanks