|
 |
|
ขอสอบถามเรื่องการแสดงข้อมูลจากฐานข้อมูล ที่ตรงกับ list menu อ่ะครับ รบกวนด้วยนะครับ |
|
 |
|
|
 |
 |
|
ผมใช้ฟังก์ชั่นนี้ในการ เลือก จังหวัด อำเภอ ตำบลอ่ะครับCode (PHP)
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListProvince_company(SelectValue)
{
member_company_register.province_company.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
member_company_register.province_company.options[member_company_register.province_company.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])
member_company_register.province_company.options[member_company_register.province_company.length]=
myOption
}<?
}
?>
}
//**** List Province (End) ***//
//**** List Amphur (Start) ***//
function ListAmphur_company(SelectValue)
{
member_company_register.subject_company.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
member_company_register.subject_company.options[member_company_register.subject_company.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])
member_company_register.subject_company.options[member_company_register.subject_company.length]=
myOption
}
<?
}
?>
}
//**** List Amphur (End) ***//
//**** List Amphur (Start) ***//
function ListDistrict_company(SelectValue)
{
member_company_register.district_company.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
member_company_register.district_company.options[member_company_register.district_company.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])
member_company_register.district_company.options[member_company_register.district_company.length]=
myOption
}
<?
}
?>
}
</script>
อันนี้เป็นแบบฟอร์มนะครับ
Code (PHP)
<tr id="geo" style="display:none;" bgcolor="#CCCCCC">
<td><label class="geo"> <span><font color="#999999"> ภูมิภาค <font color="#FF0000">*</font></font></span> </label></td>
<td><fieldset class="textbox">
<select name="geo_customer" id="geo_customer" style="background-color:#666666; width:150px;" onChange = "ListProvince(this.value)">
<option 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>
</fieldset></td>
</tr>
<tr id="province" style="display:none;" bgcolor="#CCCCCC">
<td width="25%"><label class="province"> <span><font color="#999999"> จังหวัด <font color="#FF0000">*</font></font></span> </label></td>
<td width="75%"><fieldset class="textbox">
<select name="province_customer" id="province_customer" style="background-color:#666666; width:150px;" onChange = "ListAmphur(this.value)">
<option value="">กรุณาเลือก</option>
</select>
</fieldset></td>
</tr>
<tr id="subject" style="display:none;" bgcolor="#CCCCCC">
<td width="25%"><label class="subject"> <span><font color="#999999"> อำเภอ <font color="#FF0000">*</font></font></span> </label></td>
<td width="75%"><fieldset class="textbox">
<select name="subject_customer" id="subject_customer" style="background-color:#666666; width:150px;" onChange = "ListDistrict(this.value)">
<option value="" >กรุณาเลือก</option>
</select>
</fieldset></td>
</tr>
<tr id="district" style="display:none;" bgcolor="#CCCCCC">
<td width="25%"><label class="district"> <span><font color="#999999"> ตำบล</font></span> </label></td>
<td width="75%"><fieldset class="textbox">
<select name="district_customer" id="district_customer" style="background-color:#666666; width:150px;">
<option value="">กรุณาเลือก</option>
</select>
</fieldset></td>
</tr>
ผมต้องการให้ ค่าใน listbox มันตรงกับค่าที่อยู่ในฐานข้อมูลอ่ะครับ มควร selected ยังไงครับ ขอรบกวนหน่อยนะครับ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2013-05-30 19:39:48 |
By :
lungzee |
View :
729 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมทำได้เองเลยครับ พี่น้อง ปรบมือให้ผมหน่อย ฮ่าๆ
|
 |
 |
 |
 |
Date :
2013-05-30 21:01:30 |
By :
lungzee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|