2012-03-18 4 views
0

나는 3 개의 테이블 for my_location1을 가지고 있습니다. & my_location2 & my_location3. my_ is Prefix. 위치 1 = 백작. location2 = 통계 목록. location3 = 타운리스트. 다른 테이블에 사용자 목록이 있습니다. 이제는 각 국가 별 통계 타운 (수)에서 트리 스타일 + 수중 사용자를 사용하여 모든 위치 (국가 - 통계 - 타운)를 나열하려고합니다.국가/통계/마을 + 수 목록

, 데이타베이스 참고 (이를 ?? 생성하는 방법) = 국가, PID2 =의 ID를 & PID 1을 PID 통계의 ID

my_location1 :

id ++++++ name ++++++ active 

my_location2 :

id ++++++ pid +++++++ name ++++++ active 

my_location3 :

id ++++++ pid1 +++++++ pid2 ++++++ name ++++++ active 

my_user 도와

id ++++++ name ++++++ location1 ++++++ location2 ++++++ location3 ++++++ active 

e.x

Country (print count Of users in this country) 
+++++++stats (print count Of users in this stats) 
++++++++++++town (print count Of users in this town) 
++++++++++++town (...) 
++++++++++++town (...) 
++++++++++++town (...) 
+++++++stats (...) 
++++++++++++town (...) 
+++++++stats (...) 
++++++++++++town (...) 
++++++++++++town (...) 
Country1 (...) 
+++++++stats (...) 
++++++++++++town (...) 
++++++++++++town (...) 
Country2 (...) 
+++++++stats (...) 
++++++++++++town (...) 
++++++++++++town (...) 
++++++++++++town (...) 
++++++++++++town (...) 
...more 

감사합니다.

+0

귀하의 질문은 정확히 무엇입니까? –

+0

나는 각 국가 별 통계 타운 (수)에서 트리 스타일 + aqual 사용자를 사용하여 모든 위치 (country - stats - town)를 나열하려고합니다. (생성하는 방법 ??) –

+0

사용할 treeview 컨트롤에 따라 다릅니다. 예를 들어 이미 트 리뷰 컨트롤을 선택 했습니까? http://bassistance.de/jquery-plugins/jquery-plugin-treeview/? –

답변

0

내가 코드를 확인하지 않았지만 이런 식으로 뭔가해야한다 :

function getCountries() 
{ 
    return mysql_query('SELECT c.*, (COUNT(*) from u WHERE u.location1 = c.id) AS user_count 
          from countrylist c 
          LEFT JOIN users u 
          ON u.location1 = c.id 
          WHERE c.active = 1' 
         ); 
} 

function getStats($countryId) 
{ 
    return mysql_query('SELECT s.*, (COUNT(*) from u WHERE s.location2 = s.id) AS user_count 
          from statslist s 
          LEFT JOIN users u 
          ON u.location2 = s.id 
          WHERE s.pid = ' . $countryId 
         ); 
} 

function getTowns($stateId) 
{ 
    return mysql_query('SELECT t.*, (COUNT(*) from u WHERE t.location3 = t.id) AS user_count 
          from townlist 
          LEFT JOIN users u 
          ON u.location3 = t.id 
          WHERE t.pid2 = ' . $stateId 
         ); 
} 

echo "<ul>\n"; 
while ($country = mysql_fetch_assoc(getCountries())) { 
    echo "<li>" . $country["name"] . "(" . $country["user_count"] . ")\n"; 
    echo "<ul>\n"; 

    while ($state = mysql_fetch_assoc(getStats($country["id"]))) { 
     echo "<li>" . $state["name"] . "(" . $state["user_count"] . ")\n<ul>\n"; 
     while ($town = mysql_fetch_assoc(getTowns($state["id"]))) { 
     echo "<li>" . $town["name"] . "(" . $town["user_count"] . ")</li>\n"; 
     } 
     echo "</ul>\n</li>\n"; 
    } 

    echo "<ul>\n</li>\n"; 
} 
echo "</ul>\n"; 

그것은 더욱 최적화되어야 수 있습니다,하지만 당신은 아이디어를 얻을 바랍니다. 또한 mysql 구조가 매우 중복되어 있음을 유의하십시오.

+0

도움이 되었습니까? –