PHP 우편번호 검색 삽입하기
페이지 정보
첨부파일
-
img.zip (7.4K)
72회 다운로드 | DATE : 2010-03-24 19:17:26
본문
##### write.php #####
<script type="text/javascript">
function zipfind(url, field) {
var opt = "toolbar=no, resizable=yes, scrollbars=yes, location=no, resize=no, menubar=no, directories=no, copyhistory=0, width=470, height=250, top=330, left=370";
window.open(url, 'new_window', opt);
}
</script>
<form name="hpwrite">
<input name="zip1" type="text" class="hp_input" size="13" maxlength="3" readonly /> -
<input name="zip2" type="text" class="hp_input" size="13" maxlength="3" readonly />
<a href="javascript:zipfind('zipcode.php', this);"><img src="img/zipcode_submit.gif" alt="우편번호검색" border="0" align="absmiddle" /></a>
<input name="add1" type="text" style="width:98%" readonly /><br />
<input name="add2" type="text" style="width:98%" />
<img src="./img/ok.gif" onclick="ok()" alt="온라인신청">
</form>
##### dbconfig.php #####
<?php
$mysql_host = "localhost";
$mysql_user = "아이디";
$mysql_password = "비밀번호";
$mysql_db = "디비네임";
?>
##### zipcode.php #####
<?php
include "dbconfig.php";
$dbconn = mysql_connect("$mysql_host","$mysql_user","$mysql_password") or die("데이터베이스 연결에 실패하였습니다.");
mysql_select_db($mysql_db,$dbconn);
//@mysql_query("set names utf8"); // 한글문제 생기면 주석 해제
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
<style>
body { margin: 0; font-size:12px; }
td { font-size:12px; }
a:link { font-family:"돋움"; text-decoration:none; color:#000000; line-height: 18px;}
a:active { font-family:"돋움"; text-decoration:none; color:#000000; line-height: 18px;}
a:visited { font-family:"돋움"; text-decoration:none; color:#000000; line-height: 18px;}
a:hover { font-family:"돋움"; text-decoration:underline; color:#000000; line-height: 18px;}
</style>
<title>우편번호 검색</title>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" style="background-image:url(img/zipcode_middle.gif); background-color:#FFFFFF;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="./img/zipcode_top.gif" alt=""></td>
</tr>
<tr>
<td style="letter-spacing:-1px; padding: 0 20px 17px 20px">
검색을 원하시는 주소지를 동/읍/면 단위로 입력한 다음, <font color="#ED0063"><strong>찾기 버튼</strong></font>을 누르세요.<br>
(예 : 서초동 → 서초, 부안읍 → 부안, 수내면 → 수내 )
</td>
</tr>
<tr>
<td style="padding: 0 15px 0 20px; text-align:center">
<form action="<?php echo $PHP_SELF; ?>" method="post">
<strong>읍/면/동</strong>
<input name="s" type="text" size="30" value="<?php echo $_POST['s']; ?>">
<input type="image" src="./img/zipcode_submit.gif" align="absmiddle">
</form>
</td>
</tr>
<tr>
<td style="padding: 0;">
<script type="text/javascript">
function copy(a, zip1, zip2, c) {
opener.hpwrite.zip1.value = a;
opener.hpwrite.zip2.value = b;
opener.hpwrite.add1.value = c;
opener.hpwrite.add2.focus();
window.close();
}
</script>
<table>
<?php
if ($_POST["s"]) {
$sql = "select * from zipcode where (gugun like '%{$_POST['s']}%') or (dong like '%{$_POST['s']}%') ";
//echo $sql;
$qry = mysql_query($sql, $dbconn);
?>
<?php
while($row = mysql_fetch_array($qry)) {
$zipcode = $row['zipcode'];
if(strpos($zipcode, "-") === false) {
$a = isset($zipcode) ? substr(trim($zipcode), 0, 3) : "";
$b = isset($zipcode) ? substr(trim($zipcode), 3) : "";
} else {
//echo "- 포함되어 있습니다...";
$zipcode0 = explode("-",$zipcode);
$a = $zipcode0[0];
$b = $zipcode0[1];
}
?>
<tr>
<td>
<a href="#" onclick="copy('<?php echo $a; ?>','<?php echo $b; ?>','<?php echo "{$row['sido']} {$row['gugun']} {$row['dong']} {$row['ri']}"; ?>')">
<?php echo "[{$a}-{$b}] {$row['sido']} {$row['gugun']} {$row['dong']} {$row['ri']} {$row['bunji']}"; ?></a>
</td>
</tr>
<?php
}
} else {
echo "<tr><td style=\"text-align:center; height:100px;\">검색하지 않았거나, 검색결과가 없습니다.</td></tr>";
}
?>
</table>
</td>
</tr>
<tr>
<td><img src="./img/zipcode_bottom.gif" alt="" /></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
참고자료
https://youtu.be/UNnuQBsdA30
댓글목록
등록된 댓글이 없습니다.