|
|
|
สืบเนื่องจากหัวข้อนี้ "สร้าง Dependent ListMenu เลือกข้อมูลหลักและข้อมูลย่อยเปลี่ยนตามหัวข้อหลัก" |
|
|
|
|
|
|
|
สืบเนื่องจากหัวข้อนี้ "สร้าง Dependent ListMenu เลือกข้อมูลหลักและข้อมูลย่อยเปลี่ยนตามหัวข้อหลัก"
ผมลองแปลงมาเป็น Mysqli แล้ว ข้อมูลไม่แสดงเลย ว่างเปล่า ไม่แน่ใจผิดพลาดตรงไหนครับ
Code
<?php
require_once("connection.php");
ini_set('display_errors', 1);
error_reporting(~0);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ThaiCreate.Com ListMenu</title>
<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
<?php
$intRows = 0;
$sql = "SELECT * FROM province ORDER BY PROVINCE_ID ASC ";
$query = mysqli_query($conn,$sql);
$intRows = 0;
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
$intRows++;
?>
x = <?php echo $intRows;?>;
mySubList = new Array();
strGroup = <?php echo $result["GEO_ID"];?>;
strValue = "<?php echo $result["PROVINCE_ID"];?>";
strItem = "<?php echo $result["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
}
<?php
}
?>
}
//**** 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
<?php
$intRows = 0;
$sql = "SELECT * FROM amphur ORDER BY AMPHUR_ID ASC ";
$query = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$intRows = 0;
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
$intRows++;
?>
x = <?php echo $intRows;?>;
mySubList = new Array();
strGroup = <?php echo $result["PROVINCE_ID"];?>;
strValue = "<?php echo $result["AMPHUR_ID"];?>";
strItem = "<?php echo $result["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) ***//
</script>
</head>
<form name="frmMain" action="" method="post">
Geography
<select id="ddlGeo" name="ddlGeo" onChange = "ListProvince(this.value)">
<option selected value=""></option>
<?php
$sql = "SELECT * FROM geography ORDER BY GEO_ID ASC ";
$query = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($result=mysqli_fetch_array($query,MYSQLI_ASSOC))
{
?>
<option value="<?php echo $result["GEO_ID"];?>"><?php echo $result["GEO_NAME"];?></option>
<?php
}
?>
</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>
<?php
mysqli_close($conn);
?>
Tag : PHP, CakePHP, FuelPHP
|
|
|
|
|
|
Date :
2018-05-22 11:02:15 |
By :
RabbitTie |
View :
749 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เปิด error_reporting ดูครับ
|
|
|
|
|
Date :
2018-05-22 11:06:15 |
By :
mongkon.k |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|