|
 |
|
รบกวนดูเรื่อง OnChange 2 ตาราง ให้ทีครับ มีปัญหาครับ |
|
 |
|
|
 |
 |
|
เป็นที่ shorttag มั้งครับ
|
 |
 |
 |
 |
Date :
2014-03-15 09:18:43 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตย.เก่า ๆ มีเยอะ ลองหา แล้วศึกษาเพิ่มเติมดู....
ที่มา คือ list menu พวก จังหวัด อำเภอ ตำบล นั้นแล
|
 |
 |
 |
 |
Date :
2014-03-15 10:24:02 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รบกวนดูให้ทีครับ ลองปรับแล้วครับ ตอนแรกแสดงผลในส่วนของ countryss แต่ไม่แสดงผลของ productss ต่อให้
ดู dependant-listmenu-dropdownlist จากลิ้ง ครับ
https://www.thaicreate.com/community/dependant-listmenu-dropdownlist.html
Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css" />
<title>ThaiCreate.Com ListMenu</title>
<? include"../connectDB.inc"; include("setting.php") ?>
<script language = "JavaScript">
//**** List Province (Start) ***//
function ListProvince(SelectValue)
{
frmMain.productss.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.country_name.options[frmMain.country_name.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT * FROM product ORDER BY product_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["country_code"];?>;
strValue = "<?=$objResult["product_id"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
if (mySubList[x,0] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,1])
frmMain.productss.options[frmMain.productss.length]= myOption
}
<?
}
?>
</script>
</head>
<body>
<? include"../connectDB.inc"; include("setting.php") ?>
<div id="increase">
<form name="frmMain" action="" method="post">
Geography
<select id="countryss" name="countryss" onChange = "country_name(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM country ORDER BY country_code ASC";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["country_code"];?>"><?=$objResult["country_name"];?></option>
<?
}
?>
</select>
รหัสสินค้า (ล่าสุด)
<select id="productss" name="productss" style="width:120px"></select>
</form>
</div>
<?
mysql_close($objConnect);
?>
</body>
</html>
ผมเลยลองแก้ไขอีก โดยเพิ่ม select c.*,p.* from country c,product p where c.country_id = p.country_id and order by product_id ASC ปรากฏว่า ไม่ขึ้นอ่ะไรเลยครับ
สาเหตุที่ต้องทำการ Join กันเพราะว่า
ตารางสินค้า product [product_id | product_name | product_price | category_code | country_code ]
ตารางหมวดสินค้า country [country_code | country_name]
เพื่อที่จะให้โชว์ รหัสสินค้า(product_id)ล่าสุดที่ตั้งไว้ครับ
ตัว Product_id แต่ละรหัส 2 ตัวเเรกจะไม่เหมือนกัน เช่น TH , CH , AS และก็จะตามด้วยเลข ท้าย 3 ตัว เช่น 001 , 002 ครับ
Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css" />
<title>ThaiCreate.Com ListMenu</title>
<? include"../connectDB.inc"; include("setting.php") ?>
<script language = "JavaScript">
//**** List Province (Start) ***//
function country_name(SelectValue)
{
frmMain.productss.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.productss.options[frmMain.productss.length]= myOption
<?
$intRows = 0;
$strSQL = "select c.*,p.* from country c,product p where c.country_id = p.country_id and order by product_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["country_code"];?>;
strValue = "<?=$objResult["product_id"];?>";
mySubList[x,0] = strItem;
mySubList[x,1] = strGroup;
if (mySubList[x,0] == SelectValue){
var myOption = new Option(mySubList[x,0], mySubList[x,1])
frmMain.productss.options[frmMain.productss.length]= myOption
}
<?
}
?>
</script>
</head>
<body>
<? include"../connectDB.inc"; include("setting.php") ?>
<div id="increase">
<form name="frmMain" action="" method="post">
Geography
<select id="countryss" name="countryss" onChange = "country_name(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM country ORDER BY country_code ASC";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["country_code"];?>"><?=$objResult["country_name"];?></option>
<?
}
?>
</select>
รหัสสินค้า (ล่าสุด)
<select id="productss" name="productss" style="width:120px"></select>
</form>
</div>
<?
mysql_close();
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2014-03-17 01:56:25 |
By :
sesepat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูให้ผมทีได้ไหมครับ ผมต้องทำโปรเจคส่งครับ
|
 |
 |
 |
 |
Date :
2014-03-17 11:17:41 |
By :
sesepat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่องแรกโชว์หมวดสินค้าแล้วครับ แต่ช่อง 2 ไม่โชว์เลย
รบกวนช่วยทีครับ ว่าต้องแก้ต้องไหนถึงจะแสดงช่อง 2 ครับ ไปไม่ถูกเลย
Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css" />
<title>ThaiCreate.Com ListMenu</title>
<? include"../connectDB.inc"; include("setting.php") ?>
<script language = "JavaScript">
//**** List Province (Start) ***//
function countryss(SelectValue)
{
frmMain.productss.length = 0
//*** Insert null Default Value ***//
var myOption = new Option('','')
frmMain.productss.options[frmMain.productss.length]= myOption
<?
$intRows = 0;
$strSQL = "SELECT product.* , country.* FROM product LEFT JOIN country ON product.country_code = country.country_code WHERE product.country_code = '1' ";
$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["country_code"];?>;
strValue = "<?=$objResult["product_id"];?>";
strItem = "<?=$objResult["product_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.productss.options[frmMain.productss.length]= myOption
}
<?
}
?>
</script>
</head>
<body>
<div id="increase">
<form name="frmMain" action="" method="post">
Geography
<select id="countryss" name="countryss" onChange = "countryss(this.value)">
<option selected value=""></option>
<?
$strSQL = "SELECT * FROM country ORDER BY country_code ASC";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["country_code"];?>"><?=$objResult["country_name"];?></option>
<?
}
?>
</select>
รหัสสินค้า (ล่าสุด)
<select id="productss" name="productss" style="width:120px"></select>
</form>
</div>
<?
mysql_close();
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2014-03-18 02:45:43 |
By :
sesepat |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|