views:

82

answers:

1

Hello I'm trying to get a multicolumn display (if it can be called so) with the code below here is the result: alt text. Someone can see why These leaves are broken? or tell me please which is better: a catagory table linked to a subcatery one, or an adjacency model list.

 $stmt = $conn->prepare("SELECT  node.idCat_ad ,node.".$cat_name.",(COUNT(parent.".$cat_name.") - 1) AS depth 
                       FROM cat_ad AS node 
                       CROSS JOIN cat_ad AS parent 
                       WHERE node.left_node BETWEEN parent.left_node AND parent.right_node
                       GROUP BY node.idCat_ad
                       ORDER BY node.left_node"); 

$stmt->execute();
$treeArray = $stmt->fetchAll();
?>

<div class="column_in_categories">
<div class="menucategories"><ul>

<?php
$x = 0; //counter
$num_cols = 3; //3 colums
$num_rows = count($resTree); //num columns

$result = ''; 

$newArray =array_slice($resTree,1); //removing the root tree

foreach ($newArray as $currNode) { 

   if ($currNode['depth'] ==1) { //no links in root

     $result .= '<li class="header '.$classSprites.'">' . $currNode[$cat_name] . '</li>';

  } else{ //if child, we put a link

   $result .= '<li class="subcat"><a href="#">' . $currNode[$cat_name] . '</a></li>';
  }

 $x++; // incrementing da counter

 if ($x == ceil($num_rows / $num_cols)) { //if a colunm, we clause it and begin another

   $result .= '</ul></div> <div class="menucategories"><ul><li style="display:none;">&nbsp;</li>';
   $x=0; //
  }

} 
$result .="</ul></div>";
print $result;

Serialized version link text

A: 

replace

foreach ($newArray as $currNode) { 

   if ($currNode['depth'] ==1) { //no links in root

     $result .= '<li class="header '.$classSprites.'">' . $currNode[$cat_name] . '</li>';

  } else{ //if child, we put a link

   $result .= '<li class="subcat"><a href="#">' . $currNode[$cat_name] . '</a></li>';
  }

 $x++; // incrementing da counter

 if ($x == ceil($num_rows / $num_cols)) { //if a colunm, we clause it and begin another

   $result .= '</ul></div> <div class="menucategories"><ul><li style="display:none;">&nbsp;</li>';
   $x=0; //
  }

} 

by

foreach ($newArray as $currNode) { 

 $x++; // incrementing da counter

 if ($x >= ceil($num_rows / $num_cols) and $currNode['depth'] ==1) { //if a colunm, we clause it and begin another

   $result .= '</ul></div> <div class="menucategories"><ul><li style="display:none;">&nbsp;</li>';
   $x=0; //
  }

   if ($currNode['depth'] ==1) { //no links in root

     $result .= '<li class="header '.$classSprites.'">' . $currNode[$cat_name] . '</li>';

  } else{ //if child, we put a link

   $result .= '<li class="subcat"><a href="#">' . $currNode[$cat_name] . '</a></li>';
  }

} 

This will start new columns only when new headlines start.

JochenJung
Thanks for your time. Effectively, new colunms start only after new headlines. Now a new problem occurs: if $num_cols is set to 3, I get 2 columns, if it iquals to [1 ∞]-{3} :), I get one column.
jartaud