[請益] PHP與JS的二層關聯式選單
寫了一個會從資料庫抓出數值
再塞入二層關聯式的測試程式
但是只抓得到第一個的資料
之後的都不行
想請問一下問題在哪...
謝謝
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="" rel="nofollow">http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>無標題文件</title>
</head>
<body>
<?
if($_POST[place]){
echo $_POST[place];
}
else{
?>
<FORM action="purchase.php" method="post" name=doublecombo>
<SELECT name=example onchange=redirect(this.options.selectedIndex) size=1>
<?php
$sqllink =mysql_connect("localhost","帳號","密碼");
mysql_query('SET NAMES big5');//資料庫傳過來的語言設成big5
$action="select * from college order by sn ";
$result=mysql_db_query("oga_purchase",$action,$sqllink);
while($sqlresult=mysql_fetch_array($result)){
echo "<option>".$sqlresult[name]."</option>";
}
?>
</SELECT>
<SELECT name=place size=1>
<?php
$sqllink =mysql_connect("localhost","帳號","密碼");
mysql_query('SET NAMES big5');//資料庫傳過來的語言設成big5
$action="select * from college order by sn ";
$result=mysql_db_query("oga_purchase",$action,$sqllink);
$sqlresult=mysql_fetch_array($result);
$first=$sqlresult[name];
/*以上先撈出資料庫中大項目的第一筆*/
$sqllink =mysql_connect("localhost","帳號","密碼");
mysql_query('SET NAMES big5');//資料庫傳過來的語言設成big5
$action="select * from collegeunit where belong='{$first}' order by sn ";
$result=mysql_db_query("oga_purchase",$action,$sqllink);
while($sqlresult=mysql_fetch_array($result)){
echo "<option>".$sqlresult[name]."</option>";
}
?>
</SELECT>
<SCRIPT language=JavaScript>
var groups=document.doublecombo.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()
</SCRIPT>
<?php
echo "<SCRIPT language=JavaScript>";
$sqllink =mysql_connect("localhost","帳號","密碼");
mysql_query('SET NAMES big5');//資料庫傳過來的語言設成big5
$action="select * from college order by sn ";
$result=mysql_db_query("oga_purchase",$action,$sqllink);
$i=0;
$j=0;
while($sqlresult=mysql_fetch_array($result)){
$sqllink2 =mysql_connect("localhost","帳號","密碼");
mysql_query('SET NAMES big5');//資料庫傳過來的語言設成big5
$action2="select * from collegeunit where belong='{$sqlresult[name]}' order
by sn ";
$result2=mysql_db_query("oga_purchase",$action2,$sqllink2);
while($sqlresult2=mysql_fetch_array($result2)){
echo "group[$i][$j]=new Option('$sqlresult2[name]');";
$j++;
}
$i++;
}
echo "</script>";
$j=0;
?>
<SCRIPT language=JavaScript>
var temp=document.doublecombo.place
function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}
</SCRIPT>
<input name="送出" type="submit" value="送出" />
</FORM>
<?php
} //還沒選
?>
</body>
</html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.228.177
PHP 近期熱門文章
PTT數位生活區 即時熱門文章