Author Topic: Help with loop Categories and sub-categories  (Read 1631 times)

0 Members and 1 Guest are viewing this topic.

Emanuele

  • Guest
Help with loop Categories and sub-categories
on: Mon, 25. June 2007 - 11:58:10
Hi guys,

i have this problem with loop in my template the categories and sub-categories.

Example whit image categories:



and image sub-categories



Now i use this code PHP in the template but i dont like this....Beacuse is not dinamic for the image in the table menu :(

Code: [Select]
$dati = $connetti->query("SELECT * FROM tbl_blog_categoria WHERE cat_parent_id = 0 ORDER BY cat_ordine");
while($array = $connetti->fetchArray($dati)){
echo"<tr><td height=\"25\" >&nbsp;&nbsp;
<a href=\"?azione=categorie&cat_id=$array[cat_id]\">$array[cat_nome]</a><br></td>";   

 $dati2 = $connetti->query("SELECT * FROM tbl_blog_categoria WHERE cat_parent_id = $array[cat_id]");
 while($array2 = $connetti->fetchArray($dati2)){
 $sottocategoria = substr($array2[cat_nome],0 , $caratteri);
  if($array2[cat_parent_id] == $_GET[cat_id])   
 
 echo"</tr><tr><td height=\"25\" >&nbsp;&nbsp;
 - <a href=\"?azione=categorie&cat_id=$array[cat_id]&categoria=post&parent_id=$array2[cat_id]\">$sottocategoria</a>
 <br></td>" ;

I can make?

Any example

Thanks, sorry for my english



Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Re: Help with loop Categories and sub-categories
Reply #1 on: Mon, 25. June 2007 - 13:50:29
Your problem does not contain any vlib-question. If you want to change your code please take a look at:

vlibTemplate Documentation
loop.php
nested_loops.php
Nested loops with database records

You have to understand these examples and afterwards you should change your source-code and use vLIB.

If you want to use vLIB it is important you understand how to use Arrays with two or four dimensions.

Regards,
Claus

Emanuele

  • Guest
Re: Help with loop Categories and sub-categories
Reply #2 on: Tue, 26. June 2007 - 12:07:21
ah ok now i try the new solution for change my php code.

Thanks

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
Re: Help with loop Categories and sub-categories
Reply #3 on: Tue, 26. June 2007 - 19:33:30
Off-Topic:

Quote
<a href=\"?azione=categorie&cat_id=$array[cat_id]\">

If you have the time, you should think about using mod_rewrite:
- italian tutorial
- english guide

Your URL could look like:
categorie_8.htm
or
categorie_8

But since this is off topic here, this thread will be closed.

Regards,
Claus


Last Edit: Tue, 26. June 2007 - 20:55:03 by ClausVB