|
|
|
เมนูแบบลิสที่ดึงข้อมูลจาก ฐานข้อมูลแล้ว เวลาเราจะต้องการลิงเมนูต้องเขียนโค้ดงัยครับ |
|
|
|
|
|
|
|
Code (PHP)
<script type="text/javascript">
function goToURL(value) {
window.location = "หน้าที่จะให้ไป.php?subcatalog="+value;
}
</script>
<select name="subcatalog" id="subcatalog" style="width:200px" onchange="goToURL(this.value);>
<option>xxxxx</option>
</select>
ไม่รู้แบบนี้เหรอเป่า
|
|
|
|
|
Date :
2010-03-08 15:01:50 |
By :
ไวยวิทย์ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองก่อนครับ
|
|
|
|
|
Date :
2010-03-08 15:13:18 |
By :
nongnew |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<form id="form1" name="form1" method="post" action="index.php">
<select name="catalog" id="catalog"onChange="location.href='menu.php?cat_id='+this.value;" style="width:200px">
<option value="">- àÅ×Í¡Ãкºâä -</option>
<?
$host="localhost";
$user="root";
$password="1234";
$dbname="listmenu";
$connection=mysql_connect($host,$user,$password) or die("àª×èÍÁµèÍ°Ò¹¢éÍÁÙÅäÁèä´é");
mysql_select_db($dbname) or die("äÁèÊÒÁÒöàÅ×Í¡°Ò¹¢éÍÁÙÅä´é");
$sql="select * from tb_catalog order by cat_id ASC";
$dbquery=mysql_db_query($dbname,$sql);
while($result=mysql_fetch_array($dbquery)){
if($cat_id == $result[cat_id]){ //à¾×èÍãËé áÊ´§ $cat_id ·ÕèÊ觤èÒÁÒãËé
?>
<option value="<?=$result[cat_id];?>" selected="selected"><?=$result[cat_name];?></option>
<?
}else{?>
<option value="<?=$result[cat_id];?>"><?=$result[cat_name];?></option>
<?
} }
?>
</select>
<br />
<br />
<select name="subcatalog" id="subcatalog" style="width:200px" onchange="dochange();">
<option value="">- àÅ×Í¡àÁ¹ÙÂèÍ -</option>
<?
if($cat_id != ""){ //¡Ã³Õ·Õè ÁÕè¤Ò caat_id Êè§ÁÒãËé·Ó§Ò¹
$host="localhost";
$user="root";
$password="1234";
$dbname="listmenu";
$connection=mysql_connect($host,$user,$password) or die("àª×èÍÁµèÍ°Ò¹¢éÍÁÙÅäÁèä´é");
mysql_select_db($dbname) or die("äÁèÊÒÁÒöàÅ×Í¡°Ò¹¢éÍÁÙÅä´é");
$sql_sub="select * from tb_subcatalog where cat_id = '$cat_id' ";
$dbquery_sub = mysql_db_query($dbname, $sql_sub);
while($result_sub=mysql_fetch_array($dbquery_sub)){
?>
<option value="<?=$result_sub[sub_id];?>"><?=$result_sub[sub_name];?></option>
<?
}}
?>
<br><br>
<input name="submit" type="submit" value="submit">
</form>
<script>
function dochange()
{
var opt = document.getElementById("subcatalog");
var url = "";
for(i=0;i<opt.options.length;i++){
if(opt.options[i].selected){
url = opt.options[i].value;
}
}
if(url != ""){
window.location=''+url+'/index.php';
}
}
</script>
|
|
|
|
|
Date :
2010-03-08 15:22:11 |
By :
windersun |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|