head.php 에서 보면 메뉴 카테고리를 $menu_datas 에 담는 코드가 있습니다.
카테고리 깊이가 2단이니까 for 문을 2번 돌려 $menu_datas 의 변수에 담습니다. 직관적입니다.
카테고리 플러그인 작업중에 카테고리 데이타를 변수에 담기위해 너무 많이 sql문을 실행하는 것 같아 다른 방식으로 구현해봤습니다.
테이블 형식은 다르고 깊이를 좀 자유롭게 두고 싶어습니다.
PHP변수에 담았다가 json형식으로 반환하는 코드입니다.
테이블 형식은 다음과 같습니다.
CREATE TABLE `tl_dir_zone` (
`d_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`d_path` varchar(100) DEFAULT NULL,
`d_name` varchar(100) DEFAULT NULL,
`d_type` varchar(10) DEFAULT NULL,
`d_1` varchar(255) NOT NULL DEFAULT '',
`d_2` varchar(255) NOT NULL DEFAULT '',
`d_3` varchar(255) NOT NULL DEFAULT '',
`d_4` varchar(255) NOT NULL DEFAULT '',
`d_5` varchar(255) NOT NULL DEFAULT ''
PRIMARY KEY (`d_id`),
KEY `idx_d_path` (`d_path`)
) DEFAULT CHARSET=utf8;
[code]
<?php
include './_common.php';
if($LT != 1) exit; //표현타입이 2 이면 종료(법정동처럼 너무 큰 데이타는 다른형식으로 dir_list_x.php 참조)
$json_file = G5_DATA_PATH.'/'.$DIR_TABLE.'_all.json';
$is_cache_used = true;
$cache_time = 60*60*1; // 캐쉬(1시간)
if ($is_cache_used === true && file_exists($json_file) && filectime($json_file) > time() - cache_time) {
echo file_get_contents($json_file);
exit;
}
// 필드를 적절히 수정 : json 파일 크기 줄이기 위해
$sql = "SELECT d_path, d_name, d_type, CHAR_LENGTH(d_path) dd FROM {$DIR_TABLE} ORDER BY d_path"; //dd : dir depth
$result = sql_query($sql);
$TMPM = array();
$DIRM = array();
while ($row = sql_fetch_array($result)) {
$depth = $row['dd'] / $DS;
if($depth == 1) {
$DIRM[$row['d_path']] = $row;
} else {
$p_path = substr($row['d_path'], 0 , ($DS * -1));
$TMPM[$p_path][$row['d_path']] = $row;
}
}
function tree_dir(&$p_row) {
global $TMPM;
foreach($p_row as $k=>$v) {
if(isset($TMPM[$v['d_path']])) {
$p_row[$k]['rows'] = $TMPM[$k];
tree_dir($p_row[$k]['rows']);
}
}
}
tree_dir($DIRM);
$json = json_encode($DIRM, JSON_UNESCAPED_UNICODE);
if ($is_cache_used === true) {
file_put_contents($json_file, $json);
}
echo $json;
?>
[/code]
위의 코드를 이용한 다단 selectbox 예입니다.
http://note.tloghost.kr/plugin/tl_dir/ex-niceselect.php
댓글 2개
게시글 목록
| 번호 | 제목 |
|---|---|
| 16329 |
node.js
Node.js MongoDB 정렬
|
| 16328 |
node.js
정규 표현식으로 필터링
|
| 16327 |
node.js
환경설정 - dotenv
|
| 16326 |
node.js
Node.js MongoDB 쿼리
|
| 16325 | |
| 16324 |
node.js
nodejs MongoDB Find All
|
| 16323 |
node.js
Node.js MongoDB find
|
| 16322 |
node.js
node.js MongoDB _id Field
|
| 16321 |
node.js
node.js MongoDB 여러 문서 삽입
|
| 16320 |
node.js
Node.js MongoDB Insert
|
| 16319 |
node.js
Node.js MongoDB 컬렉션 만들기
|
| 16318 |
node.js
Node.js MongoDB 데이터베이스 생성
|
| 16317 |
node.js
Node.js MongoDB 설치
1
|
| 16316 |
node.js
Node.js 전자 메일 보내기
|
| 16315 |
node.js
Node.js 파일 업로드
|
| 16310 |
node.js
node.js 이벤트 모듈
|
| 16309 |
node.js
node.js NPM
|
| 16308 |
node.js
node.js 파일삭제, 파일 이름 바꾸기
|
| 16305 |
node.js
nodejs 기초문법 - 클래스
3
|
| 16304 |
node.js
nodejs 기초문법 - 조건문 반복문
|
| 16303 |
node.js
nodejs .기초문법 변수선언 , 함수선언
|
| 16302 |
node.js
nodejs 파일 업데이트
|
| 16301 |
node.js
nodejs 파일 만들기
|
| 16300 |
node.js
nodejs 파일 읽기
1
|
| 16299 |
node.js
Node.js 쿼리 문자열 읽기 , 쿼리 문자열 분할하기
|
| 16298 |
node.js
NOde.js HTTP 모듈
|
| 16297 |
node.js
Node.js 모듈
|
| 16295 |
node.js
nods.js 시작하기
|
| 16294 |
node.js
node.js 란 2번째
|
| 16293 |
node.js
Node.js란
1
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기