怎么通过数据库来实现对应数据的输出(描述的可能有点有关问题,内详)

WBOY
Release: 2016-06-13 12:56:14
Original
1001 people have browsed it

如何通过数据库来实现对应数据的输出(描述的可能有点问题,内详)?
现在的代码,已在最后附上。我想添加办公室名称的话,直接用insert into进officename那个表就可以了
但是,这里officename与officecode是通过JS写死了。如果这样添加的话,两者的对应就有问题了,新添加的数据,是没有对应的officecode的,这就需要手动在js代码里添加,感觉这样很不合理。

所以我想的是不通过js,而是直接从数据库读取,officename表中共建立两个字段name与code 
直接通过读取数据库,将两者来进行对应,这样是否可行。需要怎样操作,最好有实例,谢谢

<br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><br />
<br />
<head><br />
<script language="javaScript"><br />
 function setofficecode()<br />
{<br />
    //获取officename/officecode的值<br />
  var officename = document.getElementById("officename").value;<br />
  var o = document.getElementById("officecode");<br />
   //条件判断<br />
   if(officename == "XX办公室"){<br />
	o.value="101";<br />
   }<br />
   else if(officename == "YY办公室"){<br />
	o.value="201";<br />
   }<br />
   else if(officename == "ZZ办公室"){<br />
	o.value="301";<br />
   }<br />
<br />
 }<br />
</script><br />
</head><br />
<br />
<br />
<form action="study3.php" method="post"><br />
<div align="center"><br />
<table><br />
  <tr><br />
  <td>办公室名称</td><br />
  <td><br />
  <select name="officename" id="officename" onchange="setofficecode()" style="width:150px;"><br />
<?php<br />
include('conn.php');<br />
 $sql="select * from officename";<br />
 $query=mysql_query($sql);<br />
 while($result=mysql_fetch_array($query)){<br />
  ?><br />
 <option value="<?=$result[officename]?>"><?=$result[officename]?></option><br />
 <?php<br />
 }<br />
 ?><br />
  </select><br />
  </td><br />
  </tr><br />
  <tr><br />
  <td>办公室号码</td><br />
  <td><input type="text" name="officecode" id="officecode" style="width:150px;" value="101"  /></td><br />
  </tr><br />
</table><br />
<br />
<input type="submit" value="提交" /><br />
</div><br />
<br />
<br />
</form><br />
Copy after login


------解决方案--------------------
改好了
<meta><br>
 <br>
<br>
<br>
 <br>
 <br>
Copy after login



  
  
  
  
  
  
  
  
办公室名称
  
  
办公室号码

 
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template