그누보드 지역 시/도, 구/군, 동/면 질문드립니다
본문
안녕하세요 지역선택을 전국 가능하게 하고싶습니다
초보라 도와주시면 감사하겠습니다 ㅠㅠ..
var cityVal = ["부산시","울산시","경상남도", "경상북도"];
<?
$sql="select distinct gugun from postcode where sido='부산시' order by ordseq";
$dbresult = sql_query($sql);
while($ary=sql_fetch_array($dbresult))
{
$gu1 .= '"'.$ary['gugun'].'",';
}
if(strlen($gu1)>0) $gu1 = substr($gu1,0,-1);
$sql="select distinct gugun from postcode where sido='울산시' order by gugun";
$dbresult = sql_query($sql);
while($ary=sql_fetch_array($dbresult))
{
$gu2 .= '"'.$ary['gugun'].'",';
}
if(strlen($gu2)>0) $gu2 = substr($gu2,0,-1);
$sql="select distinct gugun from postcode where sido='경상남도' order by gugun";
$dbresult = sql_query($sql);
while($ary=sql_fetch_array($dbresult))
{
$gu3 .= '"'.$ary['gugun'].'",';
}
if(strlen($gu3)>0) $gu3 = substr($gu3,0,-1);
$sql="select distinct gugun from postcode where sido='경상북도' order by gugun";
$dbresult = sql_query($sql);
while($ary=sql_fetch_array($dbresult))
{
$gu4 .= '"'.$ary['gugun'].'",';
}
if(strlen($gu4)>0) $gu4 = substr($gu4,0,-1);
?>
var gu1 = [<?=$gu1?>];
var gu2 = [<?=$gu2?>];
var gu3 = [<?=$gu3?>];
var gu4 = [<?=$gu4?>];
<?
$sql="select distinct gugun from postcode where sido='부산시' order by ordseq";
$dbresult = sql_query($sql);
for($i=1;$ary=sql_fetch_array($dbresult);$i++)
{
$sub_sql = " select distinct dong from postcode where sido='부산시' and gugun = '$ary[gugun]' order by dong";
$sub_result = sql_query($sub_sql);
while($sub_ary = sql_fetch_array($sub_result))
{
${'dong1_'.$i} .= '"'.$sub_ary['dong'].'",';
}
if(strlen(${'dong1_'.$i})>0) ${'dong1_'.$i} = substr(${'dong1_'.$i},0,-1);
?>
var dong1_<?=$i?> = [<?=${'dong1_'.$i}?>]
<?
}
?>
<?
$sql="select distinct gugun from postcode where sido='울산시' order by gugun";
$dbresult = sql_query($sql);
for($i=1;$ary=sql_fetch_array($dbresult);$i++)
{
$sub_sql = " select distinct dong from postcode where sido='울산시' and gugun = '$ary[gugun]' order by dong";
$sub_result = sql_query($sub_sql);
while($sub_ary = sql_fetch_array($sub_result))
{
${'dong2_'.$i} .= '"'.$sub_ary['dong'].'",';
}
if(strlen(${'dong2_'.$i})>0) ${'dong2_'.$i} = substr(${'dong2_'.$i},0,-1);
?>
var dong2_<?=$i?> = [<?=${'dong2_'.$i}?>]
<?
}
?>
<?
$sql="select distinct gugun from postcode where sido='경상남도' order by gugun";
$dbresult = sql_query($sql);
for($i=1;$ary=sql_fetch_array($dbresult);$i++)
{
$sub_sql = " select distinct dong from postcode where sido='경상남도' and gugun = '$ary[gugun]' order by dong";
$sub_result = sql_query($sub_sql);
while($sub_ary = sql_fetch_array($sub_result))
{
${'dong3_'.$i} .= '"'.$sub_ary['dong'].'",';
}
if(strlen(${'dong3_'.$i})>0) ${'dong3_'.$i} = substr(${'dong3_'.$i},0,-1);
?>
var dong3_<?=$i?> = [<?=${'dong3_'.$i}?>]
<?
}
?>
<?
$sql="select distinct gugun from postcode where sido='경상북도' order by gugun";
$dbresult = sql_query($sql);
for($i=1;$ary=sql_fetch_array($dbresult);$i++)
{
$sub_sql = " select distinct dong from postcode where sido='경상북도' and gugun = '$ary[gugun]' order by dong";
$sub_result = sql_query($sub_sql);
while($sub_ary = sql_fetch_array($sub_result))
{
${'dong4_'.$i} .= '"'.$sub_ary['dong'].'",';
}
if(strlen(${'dong4_'.$i})>0) ${'dong4_'.$i} = substr(${'dong4_'.$i},0,-1);
?>
var dong4_<?=$i?> = [<?=${'dong4_'.$i}?>]
<?
}
?>
function changeCity(o) {
guSel = document.getElementById ("combot_0");
dongSel = document.getElementById ("combot_1");
var guVal;
if(o.selectedIndex > 0)
eval ("guVal=gu" + o.selectedIndex);
else
eval ("guVal=''");
guSel.length = guVal.length + 1;
guSel.options[0] = new Option ("구/군무관", "");
dongSel.length = 1;
dongSel.options[0] = new Option (":::", "");
for (var i=0; i<guVal.length; i++) {
guSel.options[i+1] = new Option (guVal[i], guVal[i]);
}
}
function changeGu (o) {
citySel = document.getElementById ("combot_city");
guSel = document.getElementById ("combot_0");
dongSel = document.getElementById ("combot_1");
var dongVal;
if(citySel.selectedIndex > 0 && guSel.selectedIndex > 0)
eval ("dongVal=dong" + citySel.selectedIndex + "_" +guSel.selectedIndex);
else
eval ("dongVal=''");
dongSel.length = dongVal.length + 1;
dongSel.options[0] = new Option ("동/면무관", "");
for (var i=0; i<dongVal.length; i++) {
dongSel.options[i+1] = new Option (dongVal[i], dongVal[i]);
}
}
function changeCity_a (o) {
guSel = document.getElementById ("combot_0_a");
dongSel = document.getElementById ("combot_1_a");
var guVal;
if(o.selectedIndex > 0)
eval ("guVal=gu" + o.selectedIndex);
else
eval ("guVal=''");
guSel.length = guVal.length + 1;
guSel.options[0] = new Option ("구/군무관", "");
dongSel.length = 1;
dongSel.options[0] = new Option (":::", "");
for (var i=0; i<guVal.length; i++) {
guSel.options[i+1] = new Option (guVal[i], guVal[i]);
}
}
function changeGu_a (o) {
citySel = document.getElementById ("combot_city_a");
guSel = document.getElementById ("combot_0_a");
dongSel = document.getElementById ("combot_1_a");
var dongVal;
if(citySel.selectedIndex > 0 && guSel.selectedIndex > 0)
eval ("dongVal=dong" + citySel.selectedIndex + "_" +guSel.selectedIndex);
else
eval ("dongVal=''");
dongSel.length = dongVal.length + 1;
dongSel.options[0] = new Option ("동/면무관", "");
for (var i=0; i<dongVal.length; i++) {
dongSel.options[i+1] = new Option (dongVal[i], dongVal[i]);
}
}
<select name="wr_2" id="combot_city" onChange="changeCity(this)" >
<option value="" >시/도 선택</option>
<option value="부산시" <?if($wr_2=='부산시'){?>selected<?}?>>부산시</option>
<option value="울산시" <?if($wr_2=='울산시'){?>selected<?}?>>울산시</option>
<option value="경상남도" <?if($wr_2=='경상남도'){?>selected<?}?>>경상남도</option>
<option value="경상북도" <?if($wr_2=='경상북도'){?>selected<?}?>>경상북도</option>
</select>
<select name="wr_3" id="combot_0" onChange="changeGu(this)" >
<?
if($wr_2 == '부산시')
{
$sql="select distinct gugun from postcode where sido='$wr_2' ORDER BY ordseq";
$dbresult=sql_query($sql);
for($i=0;$ary=sql_fetch_array($dbresult);$i++)
{
if($i == 0)
{
?>
<option value="">부산 구/군무관</option>
<?
}
?>
<option value='<?=$ary[gugun]?>' <?if($wr_3 == $ary[gugun]){?>selected<?}?>><?=$ary[gugun]?></option>
<?
}
}
else if( $wr_2=='울산시' || $wr_2=='경상남도' || $wr_2=='경상북도' )
{
$sql="select distinct gugun from postcode where sido='$wr_2' order by gugun";
$dbresult=sql_query($sql);
for($i=0;$ary=sql_fetch_array($dbresult);$i++)
{
if($i == 0)
{
?>
<option value="">구/군무관</option>
<?
}
?>
<option value='<?=$ary[gugun]?>' <?if($wr_3 == $ary[gugun]){?>selected<?}?>><?=$ary[gugun]?></option>
<?
}
}
else
{
?>
<option value="" >구/군무관</option>
<?
}
?>
</select>
좀 알아보기 힘드시죠 죄송합니다..
원래 경남까지는 동록되어있었습니다 구/군, 동 출력 문제없음 잘 됨
우선 이렇게 경북까지만 등록을 해두었습니다
확인해보면
이렇게 구/군부터 안뜹니다..ㅠㅠ
소스보기하면
이렇게 gu4 가 빈값으로 나와요
데이터가 안나오는거같은데
혹시 지역설정을 하는 파일이 따로있나요?
아니라면 도움을 좀 얻고싶습니다..ㅠㅠ