|
|
|
ท่าน ผู้รู้ รบกวน ดู code ให้หน่อยครับ เกียวกับ การกดแก้ใข ภาค จังหวัด อำเภอ นะครับ |
|
|
|
|
|
|
|
[font=Verdana]คือว่าต้องการ กดแก้ใขแล้วให้ from ภาค จังหวัด อำเภอ ที่ ดึงมาจาก sql เป็นไปตามที่เราบันทึกไว้ครับ[/font]
code ครับ รับค่า id มาครับ
ติดปัญหา ช่วง JavaScript ครับ
Code (PHP)
<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
//*** 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) ***//
</script>
</head>
<form name="frmMain" action="" method="post">
Geography
<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))
{
?>
<option value="<?=$objResult["GEO_ID"];?>"><?=$objResult["GEO_NAME"];?></option>
<?
}
?>
</select>
Province
<select id="ddlProvince" name="ddlProvince" style="width:120px" onChange = "ListAmphur(this.value)"></select>
Amphur
<select id="ddlAmphur" name="ddlAmphur" style="width:200px"></select>
</form>
</body>
</html>
from ที่ รับ ค่า
Tag : PHP, MySQL, JavaScript, CakePHP
|
|
|
|
|
|
Date :
2011-05-30 21:33:16 |
By :
saichon_com |
View :
909 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เป็น code ตัวเดียวกับ LINK ตัวนี้ และครับ
https://www.thaicreate.com/community/dependant-listmenu-dropdownlist.html
อยากได้ คลิกแก้ไข ภาค จังหวัด อำเภอเปลียนตามโดย ไม่ต้องกลับมาเลือกใหม่ นะครับ
ถ้าใน code ปรกติ การเลือก เติมแค่ selected ก็ได้แล้ว แต่ JavaScript ไม่คอยถนัดเท่าไร
ตัวอย่าง
Code (PHP)
<option value="" selected>==== เลือก ====</option>
<?
$result = MySQL_Query("Select * From title" );
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
?>
<option value='<?=$row["title_id"]?>' selected>
<?=$row["title_name"]?>
</option>
<?
}
?>
ติดมาหลายวันแล้วครับ
|
|
|
|
|
Date :
2011-05-30 21:57:32 |
By :
saichon_com |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
code ครับ
เป็น from ที่รับค่า มาครับ
ติดตรง JavaScript
Code (PHP)
<?session_start();
/*if(!session_is_registered("login_true")) {
// ไม่ได้เข้าระบบจะกลับไปหน้า index.php
echo "<meta http-equiv='refresh' content='1;url=index.php'>" ;
exit() ;
} */
?>
<?
//สร้างการเลื่อฐานข้อมูล
$connect= mysql_connect( $hostname,$user,$password) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");
?>
<html>
<head>
<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('','')
//var myOption = new Option(''selected'')
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
//*** 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) ***//
</script>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<table width="100%">
<?
//รับค่า จาก add_search.php
$Cus_id_s=$_REQUEST['Cus_id'];
//สร้างการเลื่อฐานข้อมูล
$tb1="customer";
$tb2="title";
$tb3="dep";
$tb4="amphur";
$tb5="province";
$connect= mysql_connect( $hostname,$user,$password) or die ("ติดต่อกับฐานข้อมูล Mysql ไม่ได้ ");
mysql_select_db($db) or die("เลือกฐานข้อมูลไม่ได้");
?>
<?
$sql="Select * From $tb1,$tb2,$tb4,$tb5 where $tb1.title_id =$tb2.title_id and $tb1.aum_code =$tb4.AMPHUR_ID and $tb1.pro_code =$tb5.PROVINCE_ID and $tb1.cus_id ='$Cus_id_s'";
//$sql="Select * From $tb1,$tb2,$tb3,$tb4,$tb5 where $tb1.cus_store like '%$Cus_s' and $tb1.title_id =$tb2.title_id and $tb1.dep_id=$tb3.dep_id and $tb1.aum_code =$tb4.AMPHUR_ID and $tb1.pro_code =$tb5.PROVINCE_ID ";
$db_query=mysql_db_query($db,$sql);
$num_rows=mysql_num_rows($db_query); /* นับ Reccord ที่พบ */
$a=0;
while($a < $num_rows)
{
$result = mysql_fetch_array($db_query);
$cus_id =$result[cus_id];
$title_name=$result[title_name];
$cus_store=$result[cus_store];
$cus_name=$result[cus_name];
$cus_sername=$result[cus_sername];
$cus_add=$result[cus_add];
$cus_phont=$result[cus_phont ];
$cus_code=$result[cus_code ];
$cus_tel=$result[cus_tel];
$cus_fax=$result[cus_fax];
$dep_name=$result[dep_name];
$cus_pro=$result[cus_pro];
$AMPHUR_NAME=$result[AMPHUR_NAME];
$PROVINCE_NAME=$result[PROVINCE_NAME];
$amp_id=$result[aum_code];
$pro_id=$result[pro_code];
$geo_id=$result[GEO_ID];
$title_id=$result[title_id];
$a++;
}
?>
<tr valign="top">
<td width="60%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="457"><p align="center"><font color="#FF0000" size="3" face="MS Sans Serif"><strong>รายละเอียดผู้ค้าส่ง
Direct Sale<br></strong></font><b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b> <span class="style1"><font face="MS Sans Serif"><strong>หมายถึง</strong>
<span class="style3">ต้องกรอกข้อมูลให้ครบ</span></font></span></p>
</td>
</tr>
</table>
<form action="saveEditMember.php" method="post" name="frmMain" onSubmit="return check();"
onClick="highlight(event)">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#ddf1ff">
<tr>
<td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><table width="100%" border="0" align="center" cellpadding="5" cellspacing="1">
<tr bgcolor="#00FFFF" height="30">
<td colspan="2" bgcolor="#0066FF" width="441"><div align="center"><font face = "MS Sans Serif" color="white" size="2"><strong> ข้อมูลพื้นฐานผู้ค้าส่ง</strong></font></div></td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>ชื่อร้านค้า</b></font></td>
<td width="289"><input name="Cus_id" type="hidden" value="<?=$cus_id?>" size="28" maxlength="80"> <input name="Cus_store" type="text" value="<?=$cus_store?>" size="28" maxlength="80">
<b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b> </td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>คำนำหน้า</b></font></td>
<td width="289"> <select size="1" name="title_id">
<option value="" selected>==== เลือก ====</option>
<?
$result = MySQL_Query("Select * From title" );
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
?>
<option value='<?=$row["title_id"]?>' selected>
<?=$row["title_name"]?>
</option>
<?
}
?>
</select> <b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b>
</td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>ชื่อ</b></font>
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>นามสกุล
</b></font></td>
<td width="289"><input name="Cus_name" type="text" value="<?=$cus_name?>" size="20" maxlength="80">
<b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b><br><input name="Cus_sername" type="text" value="<?=$cus_sername?>" size="17" maxlength="80"><b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b></td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>ที่อยู่</b></font></td>
<td width="289"><input name="Cus_add" type="text" value="<?=$cus_add?>" size="17" maxlength="20"> <b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b>
</td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>อำเภอ</b></font></td>
<td width="289"> <select id="ddlAmphur" name="ddlAmphur" style="width:200px"></select><b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b>
</td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>จังหวัด</b></font></td>
<td width="289">
<select id="ddlProvince" name="ddlProvince" style="width:120px" onChange = "ListAmphur(this.value)"></select><b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b>
</td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>ภาค</b></font> </td>
<td width="289">
<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))
{
?>
<option value="<?=$objResult["GEO_ID"];?>"selected><?=$objResult["GEO_NAME"];?></option>
<?
}
?>
</select><b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b>
</td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>รหัสไปรษณีย์</b></font></td>
<td width="289"><input name="Cus_code" type="text" value="<?=$cus_code?>" size="6" maxlength="5"> <b><font color="#FF0000" size="1" face="MS Sans Serif">*ไม่มีใส่ 000000*</font></b>
</td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>เบอร์โทร</b></font></td>
<td width="289"><input name="Cus_phon" type="text" value="<?=$cus_phon?>" size="28" maxlength="10">
<b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b></td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>เบอร์โทรมือถือ</b></font></td>
<td width="289"><input name="Cus_tel" type="text" value="<?=$cus_tel?>"size="28" maxlength="10">
<b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b></td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>เบอร์
FAX</b></font></td>
<td width="289"><input name="Cus_fax" type="text" value="<?=$cus_fax?>" size="28" maxlength="10">
<b><font color="#FF0000" size="1" face="MS Sans Serif"></font></b></td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>E-mail</b></font></td>
<td width="289"><input name="Cus_email" type="text" value="<?=$cus_email?>"size="28" maxlength="80">
<b><font color="#FF0000" size="1" face="MS Sans Serif"></font></b></td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>ประเภทสินค้า</b></font></td>
<td width="289"><select size="1" name="dep_id">
<option value="" selected>==== เลือก ====</option>
<?
$result = MySQL_Query("Select * From dep");
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
?>
<option value='<?=$row["dep_id"]?>'selected>
<?=$row["dep_name"]?>
</option>
<?
}
?>
</select>
<b><font color="#FF0000" size="1" face="MS Sans Serif">**</font></b></td>
</tr>
<tr bgcolor="#FFFFFF" height="30">
<td width="141">
<p align="right"><font face = "MS Sans Serif" color="#000000" size="1"><b>รายการสินค้า</b></font></td>
<td width="289">
<b><font color="#FF0000" size="1" face="MS Sans Serif"><textarea name="cus_pro" value="<?=$cus_pro?>" rows="6" cols="27"></textarea></font></b></td>
</tr>
</table>
<p><input type="submit" name="register" value="ส่งข้อมูล">
<input name="reset" type="reset" id="reset" value="ยกเลิก">
<a href="show.php"><img src="pic/home.gif" width="18" height="18" border="0"></a></p>
</td>
</tr>
</table></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p>
</p>
</body>
</html>
|
|
|
|
|
Date :
2011-05-31 07:12:48 |
By :
chon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|