如题,写了一个多级连动的代码段,因为数据库中的记录有1万多条,在客户端脚本加载的时候很困难执行效率过低,所以在打开的时候根本无法实现连动,请问有没有更好的解决方案,也尝试过用ajax,但是在输入的时候,有的项目不能够实现连动!
<?
include_once('../include/conn.php');
$sql='select * from parts_item';//这里有1万多条记录
$result=mysql_db_query($MYSQL_DB,$sql,$conn);

$str;
while($row=mysql_fetch_array($result))
{
if($str==NULL)
{
$str=$row['parts_code'].'*'.$row['wl_code'].'*'.$row['parts_name'].'*'.$row['price'];
}
else
{
$str=$str.','.$row['parts_code'].'*'.$row['wl_code'].'*'.$row['parts_name'].'*'.$row['price'];
}
}
mysql_free_result($result);?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script src="clienthint.js"></script>
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" action="test2.php" method="post"> 
件号:
<input type="text" id="txt1" name="txt1"  onKeyUp="showHint(this.value);showHint2(this.value);showHint3(this.value)">
<br>
名称:
<input type="text" id="parts_name" name="parts_name"> 
<br>
物料编码:
<input name="wl_code" type="text" id="wl_code">
<br>
单价:
<input name="price" type="text" id="price">
<br>
数量:
<input name="count" type="text" id="count" onKeyUp="amount.value=price.value*this.value;">
<br>
金额:
<input name="amount" type="text" id="amount">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>
<script  LANGUAGE="javascript"> 

arr="<?=$str?>".split(","); 
a=arr.length 
ar=new Array() 
for (i=0;i<a;i++)

ar[i]=arr[i].split("*"); 

onecount=ar.length;

function  changeclass(str) 

lid=str;       
for  (i=0;i<onecount;i++)  
{  
if  (ar[i][0]  ==  lid) 

document.form1.parts_name.value=ar[i][2];
document.form1.wl_code.value=ar[i][1]; 
document.form1.price.value=ar[i][3];     
}     
}    
}
</script>