|
 |
|
จะทำlist box เพื่อเก็บข้อมูล77 จังหวัดทำไว้ใน db ไงครับแล้ว |
|
 |
|
|
 |
 |
|
ฐานข้อมูลลองหาเอานะครับ หาได้ทั่วไป พอดีผมมีแต่code แต่ฐานข้อมูลอยู่คนละเครื่อง ลองเปลี่ยนดูนะครับ ผมดัดแปลงไปใช้กับ sql 2008
Code (PHP)
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListAmphur(SelectValue)
{
frmMain.ddlAmphur.length = 0
frmMain.ddlDistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM amphur ORDER BY AMPHUR_NAME ";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mssql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["PROVINCE_ID"];?>;
strValue = "<?=$objResult["AMPHUR_ID"];?>";
strItem = "<?=$objResult["AMPHUR_NAME"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function ListDistrict(SelectValue)
{
frmMain.ddlDistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlDistrict.options[frmMain.ddlDistrict.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM district ORDER BY DISTRICT_NAME ";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mssql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["AMPHUR_ID"];?>;
strValue = "<?=$objResult["DISTRICT_ID"];?>";
strItem = "<?=$objResult["DISTRICT_NAME"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
mySubList[x,2] = strValue;
if (mySubList[x,1] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,2])
frmMain.ddlDistrict.options[frmMain.ddlDistrict.length]= myOption
}
<?
}
?>
}
//**** List Amphur (End) ***//
</script>
จังหวัด
<select id="ddlProvince" name="select_province" onChange = "ListAmphur(this.value)">
<option selected value="">---เลือก---</option>
<?
$strSQL = "SELECT * FROM province ORDER BY PROVINCE_NAME ";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mssql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["PROVINCE_ID"];?>"><?=$objResult["PROVINCE_NAME"];?></option>
<?
}
?>
</select>
อำเภอ
<select id="ddlAmphur" name="select_amphur" style="width:120px" onChange = "ListDistrict(this.value)"></select>
ตำบล
<select id="ddlDistrict" name="select_district" style="width:200px"></select>
|
 |
 |
 |
 |
Date :
2011-07-14 20:09:44 |
By :
MyZeus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับจะลองทำดูครับ
|
 |
 |
 |
 |
Date :
2011-07-14 22:02:07 |
By :
kk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Download ฐานข้อมูลได้ที่นี่ครับ Go to : Thailand Database ฐานข้อมูล ประเทศไทย รายชื่อ จังหวัด,อำเภอ,ตำบล ในประเทศไทย
ส่วนนี้เป็นตัวอย่างการดึงข้อมูลมาก MySQL ลงใน DropDownList
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<?
mysql_connect("localhost","root","root") or die(mysql_error());
mysql_select_db("mydatabase");
?>
<body>
<form action="phpLlistmenuDatebase2.php" method="post" name="form1">
List Menu<br>
<select name="lmName1">
<option value=""><-- Please Select Item --></option>
<?
$strSQL = "SELECT * FROM customer ORDER BY CustomerID ASC";
$objQuery = mysql_query($strSQL);
while($objResuut = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResuut["CustomerID"];?>"><?=$objResuut["CustomerID"]." - ".$objResuut["Name"];?></option>
<?
}
?>
</select>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
<?
mysql_close();
?>
Go to : PHP MySQL DropDownList / Listmenu / ListBox
|
 |
 |
 |
 |
Date :
2011-07-16 20:24:16 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|