문제

안녕하세요. 여기에서 아래 코드를 사용하여 멀티 컬럼 디스플레이를 가져 오려고합니다 (그렇게 부름받을 수있는 경우) 결과는 다음과 같습니다. alt text ...에누군가 왜 이들은 왜 깨 졌는지 알 수 있습니까?또는 더 나은 것을 알려주십시오 : 하위 카테고리 또는 인접 모델 목록에 연결된 catagory 테이블.

 $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;
.

직렬화 된 버전 링크 텍스트

도움이 되었습니까?

해결책

바꾸기

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; //
  }

} 
.

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>';
  }

} 
.

새로운 헤드 라인이 시작될 때만 새 열을 시작합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top