|
|
|
เลือก Dropdown 2 ชั้นไม่ได้ ไม่ทำงานเลยค่ะ PHP MySQL |
|
|
|
|
|
|
|
Code (PHP)
<?php require_once('Connections/conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_conn, $conn);
$query_Recordset2province = "SELECT DISTINCT bd_area.Province FROM bd_area where Tambon is not null and Amphur is not null ";
$Recordset2province = mysql_query($query_Recordset2province, $conn) or die(mysql_error());
$row_Recordset2province = mysql_fetch_assoc($Recordset2province);
$totalRows_Recordset2province = mysql_num_rows($Recordset2province);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
//**** List Amphur (Start) ***อำเภอ//
function ListAmphur(SelectValue)
{
alert('g');
form1.ddlAmphur.length = 0
form1.ddldistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
form1.ddlAmphur.options[form1.ddlAmphur.length]= myOption
<?
mysql_select_db($database_conn, $conn);
$intRows = 0;
$strSQL = "SELECT DISTINCT bd_area.Amphur, bd_area.Province FROM bd_area where Tambon is not null and Amphur is not null ";
$objQuery = mysql_query($strSQL, $conn) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["Province"];?>;
strValue = "<?=$objResult["Amphur"];?>";
strItem = "<?=$objResult["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])
form1.ddlAmphur.options[form1.ddlAmphur.length]= myOption
}
<?
}
?>
}
//**** List Amphur (End) ***อำเภอ//
//**** List District (Start) *** ตำบล//
function Listdistrict(SelectValue)
{
alert('g');
form1.ddldistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
form1.ddldistrict.options[form1.ddldistrict.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT DISTINCT bd_area.Tambon, bd_area.Amphur, bd_area.Province FROM bd_area where Tambon is not null and Amphur is not null ";
$objQuery = mysql_query($strSQL, $conn) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["Amphur"];?>;
strValue = "<?=$objResult["Tambon"];?>";
strItem = "<?=$objResult["Tambon"];?>";
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])
form1.ddldistrict.options[form1.ddldistrict.length]= myOption
}
<?
}
?>
}
//**** List District (End) ***ตำบล//
</script>
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<select name="ddlProvince" id="ddlProvince" onChange="ListAmphur(this.value)">
<option selected value=""></option>
<?php
do {
?>
<option value="<?php echo $row_Recordset2province['Province']?>"><?php echo $row_Recordset2province['Province']?></option>
<?php
} while ($row_Recordset2province = mysql_fetch_assoc($Recordset2province));
$rows = mysql_num_rows($Recordset2province);
if($rows > 0) {
mysql_data_seek($Recordset2province, 0);
$row_Recordset2province = mysql_fetch_assoc($Recordset2province);
}
?>
</select>
<select name="ddlAmphur" id="ddlAmphur" onChange="Listdistrict(this.value)">
</select>
<select name="ddldistrict" id="ddldistrict">
</select>
</form>
</body>
</html>
เลือกจังหวัดปุ๊บ อำเภอไม่ขึ้น ไม่มีalert อะไรเลยค่ะ ทั้งๆที่ลอง alert('g'); ไว้
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2015-05-21 16:21:59 |
By :
noona |
View :
978 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง View Source ในหน้า Web Browser มัน Generate ตัวรายการ ถูกไหม๊ครับ เช่น พวกรายชื่อจังหวัด / อำเภอ
|
|
|
|
|
Date :
2015-05-21 18:41:31 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|