 |
|
ตอนนี้ทำให้มันแสดงทั้งจังหวัดและอำเภอได้แล้วค่ะเหลือแต่ถ้าในฐานข้อมูลมีจังหวัดซ้ำกัน 2 จังหวัดมันก็จะขึ้นมาแสดงทั้งสองจังหวัดเลยค่ะช่วยแกทีนะค่ะพอดีอยากให้มันขึ้นมาแสดงแค่1จังหวัดแล้วมีตำบลขึ้นมาให้เลือกอ่ะค่ะช่วยแก้ที่นะค่ะ
Code (PHP)
<?
//include "connect.php";
$objConnect = mysql_connect("localhost","root","") or die("Error Connect to Database");
$objDB = mysql_select_db("training_system");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<title>Untitled Document</title>
<script language = "JavaScript">
//**** List Machine (Start) ***//
function ListAmphur(SelectValue)
{
frmMain.Amphur.length = 0
var myOption = new Option('','')
frmMain.Amphur.options[frmMain.Amphur.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM company ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
//$no_company = $objResult["no_company"];
//$com_amphur = $objResult["com_amphur"];
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["no_company"];?>;
strValue = "<?=$objResult["no_company"];?>";
strItem = "<?=$objResult["com_amphur"];?>";
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.Amphur.options[frmMain.Amphur.length]= myOption
}
<?
}
?>
}
//**** List Machine (End) ***//
</script>
</head>
<body>
<form name="frmMain" action="" method="post">
จังหวัด
<select id="Province" name="Province" onChange = "ListAmphur(this.value)">
<option selected value=""><-----เลือกจังหวัด-----></option>
<?
$strSQL = "SELECT * FROM company ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["no_company"];?>"><?=$objResult["com_province"];?></option>
<?
}
?>
</select>
อำเภอ/เขต
<select id="Amphur" name="Amphur" style="width:100px"></select>
</br>
</form>
</body>
</html>
<?
mysql_close($objConnect);
?>
Tag : PHP, MySQL, HTML/CSS
|
ประวัติการแก้ไข 2010-09-01 14:52:25
|
 |
 |
 |
 |
Date :
2010-09-01 14:51:14 |
By :
pupae010 |
View :
1052 |
Reply :
13 |
|
 |
 |
 |
 |
|
|
|
 |