|
|
|
ขอความช่วยเหลือเรื่องการเลือกจังหวัดในส่วนของหน้า แก้ไขข้อมูล ช่อง จังหวัด อำเภอ ตำบล ไม่ดึงค่าใน DB มาแสดงผล |
|
|
|
|
|
|
|
จากกรูทู้นี้
https://www.thaicreate.com/php/forum/069089.html
ช่วยหน่อยฮะ พอดีผมจะดึงค่ามาแสดงผล ในส่วนแก้ไขครับ แต่มันติดที่ว่า ช่อง จังหวัด อำเภอ ตำบล ไม่ดึงค่าใน DB มาแสดงผลด้วย
โดยผมเขียนโค้ดเพิ่มตามนี้ครับ
customer_edit.php ใช้เป็นหน้า add ข้อมูลและ edit ข้อมูล
customers_edit.php
<?
include ("check_session.php");
include ("../include/db_conn.php");
$mode = $_REQUEST["mode"];
$id = $_REQUEST["id"];
connect_db();
if (($mode == "edit") && ($id != "")) {
$sqltxt = "SELECT * FROM `customers` WHERE id=$id";
$result = mysql_query ( $sqltxt, $conn );
if ( $rs = mysql_fetch_array ( $result ) ) {
$mem_id = $rs["mem_id"];
$name = $rs["name"];
$sername = $rs["sername"];
$address = $rs["address"];
$company = $rs["company"];
$province = $rs["province"];
$phone = $rs["phone"];
$phone1 = $rs["phone1"];
$fax = $rs["fax"];
$email = $rs["email"];
$GEO_ID = $rs["GEO_ID"];
$PROVINCE_ID = $rs["PROVINCE_ID"];
$AMPHUR_ID = $rs["AMPHUR_ID"];
$DISTRICT_ID = $rs["DISTRICT_ID"];
$cus_cat_id = $rs["cus_cat_id"];
}
}
?>
<html>
<head>
<title>BandInstruments.com :: Back Office Application</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Windows-874">
<script language = "JavaScript">
//**** List Province (Start) ***จังหวัด//
function ListProvince(SelectValue)
{
frmMain.ddlProvince.length = 0
frmMain.ddlAmphur.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlProvince.options[frmMain.ddlProvince.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM province ORDER BY PROVINCE_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_fetch_array($objQuery))
{
$intRows++;
?>
x = <?=$intRows;?>;
mySubList = new Array();
strGroup = <?=$objResult["GEO_ID"];?>;
strValue = "<?=$objResult["PROVINCE_ID"];?>";
strItem = "<?=$objResult["PROVINCE_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.ddlProvince.options[frmMain.ddlProvince.length]= myOption
}
}
<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (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_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($objResult = mysql_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 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
<?
$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 = <?=$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 District (End) ***ตำบล//
</script>
<script language="JavaScript" src="include.js"></script>
</head>
<script language="javascript">
function ChkInput() {
frm = document.frmMain;
if (frm.mem_id.value == "") {
alert("Please type Spare ID !");
}
else {
if (frm.name.value == "") {
alert("Please type Name !");
}
else {
if (frm.sername.value == "") {
alert("Please type Sername !");
}else {
if (frm.company.value == "") {
alert("Please type Company !");
}else {
if (frm.address.value == "") {
alert("Please type Address !");
}
else {
frm.submit();
}}}}
}
return;
}
</script>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<script language="javascript">WriteHeader();</script>
<table width="1000" border="0" cellpadding="5" cellspacing="0" align="center">
<tr><td align="center"><br><font face='MS Sans Serif' size='3'><b>News & Public Relation Management</b></font></td></tr>
</table>
<br>
<form name="frmMain" method="post" action="customers_script.php" enctype="multipart/form-data" >
<input type="hidden" name="id" value="<?= $id ?>">
<input type="hidden" name="mode" value="<?= $mode ?>">
<input type="hidden" name="oldPicture1" value="<?= $picture1 ?>">
<input type="hidden" name="oldPicture2" value="<?= $picture2 ?>">
<input type="hidden" name="oldPicture3" value="<?= $picture3 ?>">
<input type="hidden" name="oldPicture4" value="<?= $picture4 ?>">
<input type="hidden" name="oldPicture5" value="<?= $picture5 ?>">
<input type="hidden" name="oldPicture6" value="<?= $picture6 ?>">
<input type="hidden" name="oldPicture7" value="<?= $picture7 ?>">
<input type="hidden" name="oldPicture8" value="<?= $picture8 ?>">
<input type="hidden" name="oldPicture9" value="<?= $picture9 ?>">
<input type="hidden" name="oldPicture10" value="<?= $picture10 ?>">
<input type="hidden" name="oldPicture_s" value="<?= $picture_s ?>">
<input type="hidden" name="oldPicture_special" value="<?= $picture_special ?>">
<table width="800" border="0" cellpadding="5" cellspacing="0" align="center">
<tr>
<td align="right"> </td>
<td><select name="cmbType">
<option value="">Select Type</option>
<?
$sqltxt = "select * from customer_category order by id";
$result = mysql_query ( $sqltxt, $conn );
while ( $rs = mysql_fetch_array ( $result ) ) {
print("<option value='" . $rs["id"] . "'");
if ($cus_cat_id == $rs["id"]) print(" selected");
print(">" . $rs["name"] . "</option>");
} ?>
</select></td>
</tr>
<tr>
<td width="132" align="right">รหัสลูกค้า</td>
<td width="648"><input type="text" name="mem_id" value="<?= $mem_id ?>" maxlength="255" size="/จ"></td>
</tr>
<tr>
<td align="right"><font face='MS Sans Serif' size='2'><b>ชื่อนาม - สกุล</b></font></td>
<td><input type="text" name="name" value="<?= $name ?>" maxlength="255" size="30">
<input type="text" name="sername" value="<?= $sername ?>" maxlength="255" size="30"></td>
</tr>
<tr>
<td align="right"><font face='MS Sans Serif' size='2'><b>ชื่อบริษัท / ชื่อโรงเรียน</b></font></td>
<td><input type="text" name="company" value="<?= $company ?>" maxlength="255" size="90"></td>
</tr>
<tr>
<td align="right"><font face='MS Sans Serif' size='2'><b>ที่อยู่</b></font></td>
<td><textarea name="address" rows="3" cols="90"><?= $address ?></textarea></td>
</tr>
<tr>
<td align="right"> </td>
<td>
<p>ภาค :
<select id="ddlGeo" name="ddlGeo" onChange = "ListProvince(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM geography ORDER BY GEO_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
print("<option value='" . $objResult["GEO_ID"] . "'");
if ($GEO_ID == $objResult["GEO_ID"]) print(" selected");
print(">" . $objResult["GEO_NAME"] . "</option>");
}
?>
</select>
<br>
จังหวัด :
<select id="ddlProvince" name="ddlProvince" style="width:120px" onChange = "ListAmphur(this.value)">
</select>
<br>
อำเภอ:
<select id="ddlAmphur" name="ddlAmphur" style="width:200px" onChange = "Listdistrict(this.value)">
</select>
<br>
ตำบล :
<select id="ddldistrict" name="ddldistrict" style="width:200px">
</select>
</p>
</td>
</tr>
<tr>
<td align="right"><font face='MS Sans Serif' size='2'><b>เบอร์โทรศัพท์ส่วนตัว</b></font></td>
<td><input type="text" name="phone" value="<?= $phone ?>" maxlength="" size="30"></td>
</tr>
<tr>
<td align="right"><font face='MS Sans Serif' size='2'><b>เบอร์โทรศัพท์สำนักงาน</b></font></td>
<td><input type="text" name="phone1" value="<?= $phone1 ?>" maxlength="" size="30"></td>
</tr>
<tr>
<td align="right">fax</td>
<td><input type="text" name="fax" value="<?= $fax ?>" maxlength="" size="30"></td>
</tr>
<tr>
<td align="right">Email</td>
<td><input type="text" name="email" value="<?= $email ?>" maxlength="" size="30"></td>
</tr>
<tr><td></td><td><input type="button" name="btnSave" value=" Save " onClick="javascript:ChkInput();"> <input type="button" name="btnBack" value=" Back " onClick="javascript:history.go(-1);"></td></tr>
</table>
<br><br>
</form>
</body>
</html>
<? disconnect_db(); ?>
ในส่วนของภูมิภาคที่ผมดึงมาแสดงผลได้ ผมแก้โค้ดในส่วนของ while
Code (PHP)
while($objResult = mysql_fetch_array($objQuery))
{
print("<option value='" . $objResult["GEO_ID"] . "'");
if ($GEO_ID == $objResult["GEO_ID"]) print(" selected");
print(">" . $objResult["GEO_NAME"] . "</option>");
}
แต่ใน while ของส่วนอื่นช่วยแนะนำหน่อยครับ มึนมา 3 ชม.แล้ว
ขอบพระคุณครับ
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2013-10-13 23:34:03 |
By :
slipknotbel |
View :
675 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dependent List Menu และการกำหนดค่า Default Selected Item (PHP+MySQL)
|
|
|
|
|
Date :
2013-10-14 08:55:09 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับ T^T คราวหน้าคงต้องค้นข้อมูลเพิ่มอีกซักหน่อยแล้วจะได้ไม่กวน ท่าน ADmin บ่อยๆ
|
|
|
|
|
Date :
2013-10-14 09:08:31 |
By :
slipknotbel |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|