|
 |
|
สอบถามหน่อยครับ เกี่ยวกับ listmenu หลายชั้น(2-3 ชั้น) จะสามารถใช้ข้อมูลจากตารางเดียวได้มั้ย |
|
 |
|
|
 |
 |
|
มันก็ได้น่ะครับ ขึ้นอยู่กับการออกแบบและการ Query ครับ
|
 |
 |
 |
 |
Date :
2012-03-06 16:24:27 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ออกแบบที่ว่านี้ หมายถึง การออกแบบฐานข้อมูลใช้มั้ยครับ แล้วจำเป็นมั้ยครับว่า การที่จะทำ listmenu หลายชั้น ตารางนั้นๆจะต้องมี primary key เป็นตัวเลขเสมอ (แบบว่าผมลองใช้อย่างอื่นมาเป้นคีย์ แล้วใช้มันเป็นคีย์อ้างอิง ลองส่งค่าแบบที่เคยทำได้ แต่เปลี่ยนชื่อฟิลด์ กลับไม่สามารถแสดงผลได้ครับ)
แบบแสดงผลได้
Code (PHP)
<script language = "JavaScript">
function Listnode(SelectValue)
{
form1.node.length = 0
<?
$intRows = 0;
$strSQL = "SELECT * FROM pm ORDER BY node_H 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["id"];?>; // จุดที่แตกต่าง
strValue = "<?=$objResult["location"];?>";
strItem = "<?=$objResult["location"];?>";
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])
form1.node.options[form1.node.length]= myOption
}
<?
}
?>
}
</script>
<select id="location" name="location" style="width:170px" onchange="Listnode(this.value)">
<option selected="selected" value=""></option>
<?php
$strSQL = "SELECT * FROM pm ORDER BY node_H";
$objQuery = mysql_query($strSQL)or die("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["id"];?>"> // จุดที่แตกต่าง
<?=$objResult["node_H"];?> | <?=$objResult["location"];?>
</option>
<?
}
?>
</select>
แบบแสดงผลไม่ได้
Code (PHP)
<script language = "JavaScript">
function Listnode(SelectValue)
{
form1.node.length = 0
<?
$intRows = 0;
$strSQL = "SELECT * FROM pm ORDER BY node_H 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["node_H"];?>; // จุดที่แตกต่าง
strValue = "<?=$objResult["location"];?>";
strItem = "<?=$objResult["location"];?>";
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])
form1.node.options[form1.node.length]= myOption
}
<?
}
?>
}
</script>
<select id="location" name="location" style="width:170px" onchange="Listnode(this.value)">
<option selected="selected" value=""></option>
<?php
$strSQL = "SELECT * FROM pm ORDER BY node_H";
$objQuery = mysql_query($strSQL)or die("Error Query [".$strSQL."]");
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["node_H"];?>"> // จุดที่แตกต่าง
<?=$objResult["node_H"];?> | <?=$objResult["location"];?>
</option>
<?
}
?>
</select>
|
ประวัติการแก้ไข 2012-03-06 16:51:28
 |
 |
 |
 |
Date :
2012-03-06 16:49:56 |
By :
akkaneetha |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|