묻고답하기
foreach 문제
2012.11.05 16:14
우편번호 찾아오는 로직인데요
select action 을 거쳐서 (executeQuery 실행) 가져온 배열값을
foreach 문으로 table 에 나타내려고 하는데
select 결과가 여러개 일때는 잘 보이는데
select 결과가 한 개 일때는 아예 값을 못가져오는지 화면에 뿌려지지 않습니다 (빈 값으로 뿌려짐...무한루프 도는 걸까요?...ㅠㅠ)
무슨 문제가 있는 걸까요?
==== 화면 Layout (search.html)=====================================================
<table width="95%" align=center cellpadding=5 cellspacing=0 border=0 >
<tr>
<td>
<form action="./" method="get">
<input type="hidden" name="module" value="{$module}" />
<input type="hidden" name="act" value="{$act}" />
<input type="text" name="searchDong" value="<?=$_GET['searchDong']?>" />
<span class="button"><input type="submit" value="{$lang->hsSearch}" /></span>
</form>
</td>
</tr>
<tr>
<td height="300" style="padding:10px" valign="top">
<div style="overflow:scroll;overflow-x:hidden; width:500; height:300px; padding:10px;">
<table width="100%" align=center cellpadding=5 cellspacing=0 border=0 >
<!--@foreach($searchZip as $Key => $Val)-->
{@
$addr01 = "";
$addr02 = "";
$eaddr01 = "";
$eaddr02 = "";
if ($Val->sido)
$addr01[] = $Val->sido;
if ($Val->gungu)
$addr01[] = $Val->gungu;
if ($Val->dong)
$addr01[] = $Val->dong;
if ($Val->ri)
$addr01[] = $Val->ri;
if ($Val->doseo)
$addr02[] = $Val->doseo;
if ($Val->building)
$addr02[] = $Val->building;
$addr01Txt = @implode(" ", $addr01);
$addr02Txt = @implode(" ", $addr02);
if ($Val->e_ri)
$eaddr01[] = $Val->e_ri;
if ($Val->e_dong)
$eaddr01[] = $Val->e_dong;
if ($Val->e_gungu)
$eaddr01[] = $Val->e_gungu;
if ($Val->e_sido)
$eaddr01[] = $Val->e_sido;
if ($Val->e_building)
$eaddr02[] = $Val->e_building;
if ($Val->e_doseo)
$eaddr02[] = $Val->e_doseo;
$eaddr01Txt = @implode(", ", $eaddr01);
$eaddr02Txt = @implode(", ", $eaddr02);
}
<tr>
<td width="10%">[{$Val->zipcode}]</td>
<td width="90%"><a href="#top" onclick="funcCheckZip('{$Val->zipcode}', '{$Val->e_sido}', '{$Val->e_gungu}', '{$addr01Txt}', '{$addr02Txt}' , '{$eaddr01Txt}', '{$eaddr02Txt}' ); return false;">{$addr01Txt} {$Val->doseo} {$Val->bunji} {$Val->building}</a></td>
</tr>
<!--@end-->
</table>
</div>
</td>
</tr>
<tr>
<td align="center"><span class="button"><input type="button" value="{$lang->hsCloseTxt}" onclick="window.close();return false;"></span></td>
</tr>
</table>
==== Submit function =====================================================
function dispHsapplySearchZipCode() {
$args->sdong = Context::get('searchDong');
if ($args->sdong) {
$output = executeQuery('hsapply.getAddressZip', $args);
Context::set('searchZip', $output->data);
}
$this->setLayoutFile('popup_layout');
$this->setTemplateFile('search');
}
==== Query (getAddressZip.xml) ================================================================
<query id="getAddressZip" action="select">
<tables>
<table name="hsapply_zipcode" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="like" column="zipcode" var="sdong" pipe="or" />
<condition operation="like" column="dong" var="sdong" pipe="or" />
<condition operation="like" column="ri" var="sdong" pipe="or" />
<condition operation="like" column="doseo" var="sdong" pipe="or" />
<condition operation="like" column="building" var="sdong" pipe="or" />
<condition operation="like" column="e_dong" var="sdong" pipe="or" />
<condition operation="like" column="e_ri" var="sdong" pipe="or" />
<condition operation="like" column="e_doseo" var="sdong" pipe="or" />
<condition operation="like" column="e_building" var="sdong" pipe="or" />
</conditions>
</query>
댓글 2
-
송동우
2012.11.05 16:39
-
Daniel
2012.11.06 10:05
너무 감사합니다~!! -
CMD
2012.11.05 16:42
executeQuery() 함수 대신에 executeQueryArray() 함수를 사용하시면 무조건 배열로 리턴해요~
-
Daniel
2012.11.06 10:06
금방 되네요...ㅠㅠ...넘 감사요~!!
결과값이
하나이상일때는 배열로, 하나일때는 배열이 아닙니다.
그러면
is_array 함수를 사용해서
배열일 때와 아닐때를 구별해서 처리해야 할 겁니다.