001.
<?php
002.
003.
004.
005.
$objConnect
= mysql_connect(
"localhost"
,
"root"
,
"root"
)
or
die
(
"Error Connect to Database"
);
006.
$objDB
= mysql_select_db(
"thailand"
);
007.
@mysql_query(
"SET NAMES UTF8"
);
008.
?>
009.
<html>
010.
<head>
011.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
>
012.
<title>ThaiCreate.Com ListMenu</title>
013.
<script language =
"JavaScript"
>
014.
015.
016.
function
ListProvince(SelectValue)
017.
{
018.
frmMain.ddlProvince.length = 0
019.
frmMain.ddlAmphur.length = 0
020.
021.
022.
var
myOption =
new
Option(
''
,
''
)
023.
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
024.
025.
<?
026.
$intRows
= 0;
027.
$strSQL
=
"SELECT * FROM province ORDER BY PROVINCE_ID ASC "
;
028.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
029.
$intRows
= 0;
030.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
031.
{
032.
$intRows
++;
033.
?>
034.
x = <?=
$intRows
;?>;
035.
mySubList =
new
Array();
036.
037.
strGroup = <?=
$objResult
[
"GEO_ID"
];?>;
038.
strValue =
"<?=$objResult["
PROVINCE_ID
"];?>"
;
039.
strItem =
"<?=$objResult["
PROVINCE_NAME
"];?>"
;
040.
mySubList[x,0] = strItem;
041.
mySubList[x,1] = strGroup;
042.
mySubList[x,2] = strValue;
043.
if
(mySubList[x,1] == SelectValue){
044.
var
myOption =
new
Option(mySubList[x,0], mySubList[x,2])
045.
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
046.
}
047.
<?
048.
}
049.
?>
050.
}
051.
052.
053.
054.
055.
function
ListAmphur(SelectValue)
056.
{
057.
frmMain.ddlAmphur.length = 0
058.
059.
060.
var
myOption =
new
Option(
''
,
''
)
061.
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
062.
063.
<?
064.
$intRows
= 0;
065.
$strSQL
=
"SELECT * FROM amphur ORDER BY AMPHUR_ID ASC "
;
066.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
067.
$intRows
= 0;
068.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
069.
{
070.
$intRows
++;
071.
?>
072.
x = <?=
$intRows
;?>;
073.
mySubList =
new
Array();
074.
075.
strGroup = <?=
$objResult
[
"PROVINCE_ID"
];?>;
076.
strValue =
"<?=$objResult["
AMPHUR_ID
"];?>"
;
077.
strItem =
"<?=$objResult["
AMPHUR_NAME
"];?>"
;
078.
mySubList[x,0] = strItem;
079.
mySubList[x,1] = strGroup;
080.
mySubList[x,2] = strValue;
081.
082.
if
(mySubList[x,1] == SelectValue){
083.
var
myOption =
new
Option(mySubList[x,0], mySubList[x,2])
084.
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
085.
}
086.
<?
087.
}
088.
?>
089.
}
090.
091.
092.
</script>
093.
094.
095.
</head>
096.
<body OnLoad=
"setDefault()"
>
097.
<script language=
"JavaScript"
>
098.
function
setDefault()
099.
{
100.
<?
101.
102.
$strGeography
=
"3"
;
103.
$strProvince
=
"20"
;
104.
$strAmphur
=
"252"
;
105.
?>
106.
107.
<?
108.
109.
if
(
$strGeography
!=
""
)
110.
{
111.
?>
112.
var
objGeo=document.frmMain.ddlGeo;
113.
for
(x=0;x<objGeo.length;x++)
114.
{
115.
if
(objGeo.options[x].value==
"<?=$strGeography?>"
)
116.
{
117.
objGeo.options[x].selected = true;
118.
break
;
119.
}
120.
}
121.
122.
ListProvince(<?=
$strGeography
;?>)
123.
<?
124.
}
125.
?>
126.
127.
<?
128.
129.
if
(
$strProvince
!=
""
)
130.
{
131.
?>
132.
var
objProvince=document.frmMain.ddlProvince;
133.
for
(x=0;x<objProvince.length;x++)
134.
{
135.
if
(objProvince.options[x].value==
"<?=$strProvince?>"
)
136.
{
137.
objProvince.options[x].selected = true;
138.
break
;
139.
}
140.
}
141.
142.
ListAmphur(<?=
$strProvince
;?>)
143.
<?
144.
}
145.
?>
146.
147.
<?
148.
149.
if
(
$strAmphur
!=
""
)
150.
{
151.
?>
152.
var
objAmphur=document.frmMain.ddlAmphur;
153.
for
(x=0;x<objAmphur.length;x++)
154.
{
155.
if
(objAmphur.options[x].value==
"<?=$strAmphur?>"
)
156.
{
157.
objAmphur.options[x].selected = true;
158.
break
;
159.
}
160.
}
161.
<?
162.
}
163.
?>
164.
165.
}
166.
</script>
167.
<form name=
"frmMain"
action=
""
method=
"post"
>
168.
Geography
169.
<select id=
"ddlGeo"
name=
"ddlGeo"
onChange =
"ListProvince(this.value)"
>
170.
<option selected value=
""
></option>
171.
<?
172.
$strSQL
=
"SELECT * FROM geography ORDER BY GEO_ID ASC "
;
173.
$objQuery
= mysql_query(
$strSQL
)
or
die
(
"Error Query ["
.
$strSQL
.
"]"
);
174.
while
(
$objResult
= mysql_fetch_array(
$objQuery
))
175.
{
176.
?>
177.
<option value=
"<?=$objResult["
GEO_ID
"];?>"
><?=
$objResult
[
"GEO_NAME"
];?></option>
178.
<?
179.
}
180.
?>
181.
</select>
182.
183.
Province
184.
<select id=
"ddlProvince"
name=
"ddlProvince"
style=
"width:120px"
onChange =
"ListAmphur(this.value)"
></select>
185.
186.
Amphur
187.
<select id=
"ddlAmphur"
name=
"ddlAmphur"
style=
"width:200px"
></select>
188.
</form>
189.
</body>
190.
</html>
191.
<?
192.
mysql_close(
$objConnect
);
193.
?>