|
|
|
ช่วยดูโค๊ดให้หน่อยครับ พอดี select โค๊ดออกมาโหมดแล้วแต่เหลืออำเภอไม่ออก ทั้งๆที่ตำบอลก็อ้างมาจากอำเภอแท้ๆ |
|
|
|
|
|
|
|
พอดีผมจะ select มาแก้ไข มันมา จังหวัด และตำบล อย่างเดียว อำเภอหายซะอย่างนั้น แต่ตำบลโผล่อย่างถูกต้อง เลยมึนเลย ใครพอทราบต้องแก้ตรงไหนครับ เพราะผมเชคค่าไอดีต่างๆก็ไม่ตรงหมดแล้ว
อันนี้ภาพครับ
--> ดัตแปลจากโค๊ดแอดมินนี่ https://www.thaicreate.com/php/forum/064296.html
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("thailand")or die("Error Connect to java");
@mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ThaiCreate.Com ListMenu</title>
<script language = "JavaScript">
//**** List Amphur (Start) ***//
function ListAmphur(SelectValue)
{
frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
<?php
$intRows = 0;
$strSQL = "SELECT * FROM amphur ORDER BY AMPHUR_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?php echo $intRows;?>;
mySubList = new Array();
strGroup = <?php echo $objResult["PROVINCE_ID"];?>;
strValue = "<?php echo $objResult["AMPHUR_ID"];?>";
strItem = "<?php echo $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
}
<?php
}
?>
}
//**** List Amphur (End) ***//
//**** List District (Start) ***//
function ListDistrict(SelectValue)
{
frmMain.ddlDistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlDistrict.options[frmMain.ddlDistrict.length]= myOption
<?php
$intRows = 0;
$strSQL = "SELECT * FROM district ORDER BY DISTRICT_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?php echo $intRows;?>;
mySubList = new Array();
strGroup = <?php echo $objResult["AMPHUR_ID"];?>;
strValue = "<?php echo $objResult["DISTRICT_ID"];?>";
strItem = "<?php echo $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
}
<?php
}
?>
}
//**** List District (End) ***//
</script>
</head>
<body OnLoad="setDefault()">
<script language="JavaScript">
function setDefault()
{
<?
/*** ค่า Default ที่ได้จากการจัดเก็บ ***/
/*
$strGeography = "1";
$strProvince = "43";
$strAmphur= "636";
$strDistrict= "5711";
*/
$ID = $_GET['ProID'];
$sql = "SELECT * FROM editdatethai
INNER JOIN province ON editdatethai.Province = province.PROVINCE_ID
INNER JOIN amphur ON editdatethai.Amphur = amphur.AMPHUR_ID
INNER JOIN district ON editdatethai.District = district.DISTRICT_ID
WHERE ID = '$ID'";
$result = mysql_query($sql) or die("Error Query [".$sql."]");
$rows = mysql_fetch_array($result);
$strAmphur = $rows['AMPHUR_ID'];
$strDistrict= $rows['DISTRICT_ID'];
?>
<?
/*** Default Amphur ***/
if($strAmphur != "")
{
?>
var objAmphur=document.frmMain.ddlAmphur;
for (x=0;x<objAmphur.length;x++)
{
if (objAmphur.options[x].value=="<?=$strAmphur?>")
{
objAmphur.options[x].selected = true;
break;
}
}
ListDistrict(<?=$strAmphur;?>)
<?
}
?>
<?
/*** Default District ***/
if($strDistrict != "")
{
?>
var objDistrict=document.frmMain.ddlDistrict;
for (x=0;x<objDistrict.length;x++)
{
if (objDistrict.options[x].value=="<?=$strDistrict?>")
{
objDistrict.options[x].selected = true;
break;
}
}
<?
}
?>
}
</script>
<?php
$ID = $_GET['ProID'];
$sql = "SELECT * FROM editdatethai
INNER JOIN province ON editdatethai.Province = province.PROVINCE_ID
INNER JOIN amphur ON editdatethai.Amphur = amphur.AMPHUR_ID
INNER JOIN district ON editdatethai.District = district.DISTRICT_ID
WHERE ID = '$ID'";
$result = mysql_query($sql) or die("Error Query [".$sql."]");
$rows = mysql_fetch_array($result);
?>
<form name="frmMain" action="" method="post">
Province
<select id="ddlProvince" name="ddlProvince" onChange = "ListAmphur(this.value)">
<option selected value=""></option>
<?php
$strSQL = "SELECT * FROM province ORDER BY PROVINCE_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery)){
?>
<!--<option value="<?php echo $objResult["GEO_ID"];?>"><?php echo $objResult["GEO_NAME"];?></option>-->
<option value="<?php echo $objResult['PROVINCE_ID']; ?>"
<?php
if($objResult['PROVINCE_ID']==$rows['Province']){
echo "selected='selected'";
}
?>
><?=$objResult['PROVINCE_NAME'];?>
</option>
<?php
}
?>
</select>
Amphur
<select id="ddlAmphur" name="ddlAmphur" style="width:200px" onChange = "ListDistrict(this.value)"></select>
District
<select id="ddlDistrict" name="ddlDistrict" style="width:200px"></select>
<input type="submit" name="btnSubmit" value="submit">
</form>
</body>
</html>
<?php
mysql_close($objConnect);
?>
Tag : PHP, MySQL, JavaScript
|
|
|
|
|
|
Date :
2014-12-13 23:06:09 |
By :
shield |
View :
940 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองเอาโค้ดมาแก้แค่ server user pass แล้วก็ run ได้ปกตินะ
|
ประวัติการแก้ไข 2014-12-14 00:47:22
|
|
|
|
Date :
2014-12-14 00:46:20 |
By :
tongkamlekdee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ก็ปกตินะครับก็แค่ใส่ config ฐานข้อมูลก็ใช้ได้แล้ว ลองดูในฐานข้อมูลดูครับว่าตารางครบไหม มีตาราง amphur อยู่หรือเปล่า
|
ประวัติการแก้ไข 2014-12-14 01:09:48
|
|
|
|
Date :
2014-12-14 01:06:45 |
By :
LAGO |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
ดูดีๆเลยเห็นว่าคุณลืมโหลดอำเภอให้แทรก ListAmphur(<?=$rows['PROVINCE_ID']?>) หลังบรรทัดที่ 122 ก็ใช้ได้แล้ว
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("test")or die("Error Connect to java");
@mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ThaiCreate.Com ListMenu</title>
<script language = "JavaScript">
//**** List Amphur (Start) ***//
function ListAmphur(SelectValue)
{
frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlAmphur.options[frmMain.ddlAmphur.length]= myOption
<?php
$intRows = 0;
$strSQL = "SELECT * FROM amphur ORDER BY AMPHUR_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?php echo $intRows;?>;
mySubList = new Array();
strGroup = <?php echo $objResult["PROVINCE_ID"];?>;
strValue = "<?php echo $objResult["AMPHUR_ID"];?>";
strItem = "<?php echo $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
}
<?php
}
?>
}
//**** List Amphur (End) ***//
//**** List District (Start) ***//
function ListDistrict(SelectValue)
{
frmMain.ddlDistrict.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlDistrict.options[frmMain.ddlDistrict.length]= myOption
<?php
$intRows = 0;
$strSQL = "SELECT * FROM district ORDER BY DISTRICT_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?php echo $intRows;?>;
mySubList = new Array();
strGroup = <?php echo $objResult["AMPHUR_ID"];?>;
strValue = "<?php echo $objResult["DISTRICT_ID"];?>";
strItem = "<?php echo $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
}
<?php
}
?>
}
//**** List District (End) ***//
</script>
</head>
<body OnLoad="setDefault()">
<script language="JavaScript">
function setDefault()
{
<?
/*** ค่า Default ที่ได้จากการจัดเก็บ ***/
/*
$strGeography = "1";
$strProvince = "43";
$strAmphur= "636";
$strDistrict= "5711";
*/
$ID = $_GET['ProID'];
$sql = "SELECT * FROM editdatethai
INNER JOIN province ON editdatethai.Province = province.PROVINCE_ID
INNER JOIN amphur ON editdatethai.Amphur = amphur.AMPHUR_ID
INNER JOIN district ON editdatethai.District = district.DISTRICT_ID
WHERE ID = '$ID'";
$result = mysql_query($sql) or die("Error Query [".$sql."]");
$rows = mysql_fetch_array($result);
$strAmphur = $rows['AMPHUR_ID'];
$strDistrict= $rows['DISTRICT_ID'];
?>
ListAmphur(<?=$rows['PROVINCE_ID']?>) ; /*เรียกใช้งานโหลดอำเภอตรงนี้*/
<?
/*** Default Amphur ***/
if($strAmphur != "")
{
?>
var objAmphur=document.frmMain.ddlAmphur;
for (x=0;x<objAmphur.length;x++)
{
if (objAmphur.options[x].value=="<?=$strAmphur?>")
{
objAmphur.options[x].selected = true;
break;
}
}
ListDistrict(<?=$strAmphur;?>)
<?
}
?>
<?
/*** Default District ***/
if($strDistrict != "")
{
?>
var objDistrict=document.frmMain.ddlDistrict;
for (x=0;x<objDistrict.length;x++)
{
if (objDistrict.options[x].value=="<?=$strDistrict?>")
{
objDistrict.options[x].selected = true;
break;
}
}
<?
}
?>
}
</script>
<?php
$ID = $_GET['ProID'];
$sql = "SELECT * FROM editdatethai
INNER JOIN province ON editdatethai.Province = province.PROVINCE_ID
INNER JOIN amphur ON editdatethai.Amphur = amphur.AMPHUR_ID
INNER JOIN district ON editdatethai.District = district.DISTRICT_ID
WHERE ID = '$ID'";
$result = mysql_query($sql) or die("Error Query [".$sql."]");
$rows = mysql_fetch_array($result);
?>
<form name="frmMain" action="" method="post">
Province
<select id="ddlProvince" name="ddlProvince" onChange = "ListAmphur(this.value)">
<option selected value=""></option>
<?php
$strSQL = "SELECT * FROM province ORDER BY PROVINCE_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery)){
?>
<!--<option value="<?php echo $objResult["GEO_ID"];?>"><?php echo $objResult["GEO_NAME"];?></option>-->
<option value="<?php echo $objResult['PROVINCE_ID']; ?>"
<?php
if($objResult['PROVINCE_ID']==$rows['Province']){
echo "selected='selected'";
}
?>
><?=$objResult['PROVINCE_NAME'];?>
</option>
<?php
}
?>
</select>
Amphur
<select id="ddlAmphur" name="ddlAmphur" style="width:200px" onChange = "ListDistrict(this.value)"></select>
District
<select id="ddlDistrict" name="ddlDistrict" style="width:200px"></select>
<input type="submit" name="btnSubmit" value="submit">
</form>
</body>
</html>
<?php
mysql_close($objConnect);
?>
|
ประวัติการแก้ไข 2014-12-14 01:12:47
|
|
|
|
Date :
2014-12-14 01:11:31 |
By :
tongkamlekdee |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณทุกท่านครับ ได้แล้วครับ แก้ บรรทัด 122 จริงๆด้วย
|
|
|
|
|
Date :
2014-12-15 15:11:41 |
By :
shield |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|