|
|
|
list menu ที่ สอง.. Dependant List Menu....ยังไม่เปลี่ยนอ้ะค้ะ |
|
|
|
|
|
|
|
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("motor");
@mysql_query("SET NAMES UTF8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language = "JavaScript">
//**** List Class (Start) ***//
function ListClass(SelectValue)
{
frmMain.ddlClass.length = 0
frmMain.ddlSpare.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlClass.options[frmMain.ddlClass.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM class ORDER BY class_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["brand_id"];?>;
strValue = "<?=$objResult["class_id"];?>";
strItem = "<?=$objResult["class_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.ddlClass.options[frmMain.ddlClass.length]= myOption
}
<?
}
?>
}
//**** List class (End) ***//
//**** List spare (Start) ***//
function ListSpare(SelectValue)
{
frmMain.ddlSpare.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.ddlSpare.options[frmMain.ddlSpare.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM spare_type ORDER BY spt_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["class_id"];?>;
strValue = "<?=$objResult["spt_id"];?>";
strItem = "<?=$objResult["spt_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.ddlSpare.options[frmMain.ddlSpare.length]= myOption
}
<?
}
?>
}
//**** List spare (End) ***//
</script>
</head>
<form name="frmMain" action="" method="post">
Brand
<select id="ddlBrand" name="ddlBrand" onChange = "ListClass(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM brand ORDER BY brand_id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["brand_id"];?>"><?=$objResult["brand_name"];?></option>
<?
}
?>
</select>
class
<select id="ddlClass" name="ddlClass" style="width:120px" onChange = "ListSpare(this.value)"></select>
spare
<select id="ddlSpare" name="ddlSpare" style="width:200px"></select>
</form>
</body>
</html>
<?
mysql_close($objConnect);
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2013-05-09 11:51:20 |
By :
lookpla26 |
View :
710 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง View Source ในหน้า Web Browser มาให้ดูหน่อยครับ
|
|
|
|
|
Date :
2013-05-09 12:17:29 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...remove by mr.win
|
|
|
|
|
Date :
2013-05-09 13:24:05 |
By :
lookpla26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|