foreach로 메뉴명들을 뽑고있는데..
예를들면...
Copy
$sql = select * from category where depth=1; //1뎁스인애들불러오기while($res = db_fetch_array($sql)) {$depth1[] =$res;}foreach ($depth1 as $key =>$val) {echo $val['name']; //1뎁스명애들 출력됨. 그다음 이어서 2뎁스애들을 불러와야하는데 여기서 어떻게해야할지를 모르겠습니다..}
db category 테이블에서 1뎁스의 idx 값을 가지고 2뎁스를 찾아 불러와야하는데
$depth2 = select * from category where depth=2 and parent=$depth1['idx'];
while로는 할 수있겠는데 foreach로는 도저히 머리가 돌아가지 않네요...
제발 알려주세요ㅜㅜ
|
답변 3개 / 댓글 2개
채택된 답변
+20 포인트
$sql = "select * from category where depth=2";
while($res = db_fetch_array($sql)) $depth2[$row['parent']][] = $res;
$sql = "select * from category where depth=1";
while($res = db_fetch_array($sql))
foreach ($depth2[$res['idx']] as $v) echo $v;
거의다 하신거 같은데요
Copy
$depth2 = "select * from category where depth=2 and parent=$val['idx']"; // 변수를 맞는걸로 사용하시면되요
답변을 작성하려면 로그인이 필요합니다.