从数组填充下拉框
我对此有点陌生,但我正在尝试从 sql 语句填充一个数组,该语句从表中提取多个许可证号。
因此,在表中每个人都可以拥有多个许可证,我需要存储所有许可证号并通过 javascript 将它们显示在下拉框中。我从数组中获取信息,但信息以重复的方式显示,其中第一项位于下拉框中,然后使用第二项重新创建下拉框,依此类推,直到所有数组信息都显示出来显示。 我需要这种模式不重复,但数组中的项目填充页面上的一个下拉框。
这是代码:
ResultSet rsTagCheck = stmt.executeQuery("SELECT PARKING.XKRPRMT.XKRPRMT_PIDM, PARKING.XKRPRMT.XKRPRMT_STATUS, PARKING.XKRPRMT.XKRPRMT_EXPIRE_YR, PARKING.XKRPRMT.XKRPRMT_TAG FROM PARKING.XKRPRMT WHERE XKRPRMT_PIDM ='" + BannerID + "'");
while (rsTagCheck.next()){
String TagNum = rsTagCheck.getString("XKRPRMT_TAG");
String[] tag = new String[101];
for (int i = 0; i < tag.length; i++)
tag[i] = TagNum;
%>
<table style="border:transparent" style="width:100%">
<tr>
<td style ="width: 300px;">
<select style="width:150px;"tabindex="5" name="Tag">
<option></option><option>T - Temporary</option>
<option><%=tag[0]%></option>
<option><%=tag[1]%></option>
<option><%=tag[2]%></option>
<option><%=tag[3]%></option>
<option><%=tag[4]%></option>
<option><%=tag[5]%></option>
</select>
</td>
</table>
<div style="width:200px;"><input type="submit"value="Add Tag">
</div>
<button onclick="window.location='startup.jsp'">Home</button>
<%}
rsTagCheck.close();
stmt.close();
conn.close();
%>
我需要帮助
任何帮助将不胜感激。谢谢
I am kinda new to this, but I am trying to fill an array from a sql statement that pulls several permit numbers from a table.
So in the table every person can have multiple permits, I need to store all the permit numbers and display them in a drop down box via javascript. I get the information from the array but the information is displayed in a repeating fashion where the first item is in the drop down box, then it re-creates the drop down box with the second item, and so on until all the array information is displayed.
I need this pattern not to repeat, but the items in the array fill ONE drop down box on the page.
Here is the code:
ResultSet rsTagCheck = stmt.executeQuery("SELECT PARKING.XKRPRMT.XKRPRMT_PIDM, PARKING.XKRPRMT.XKRPRMT_STATUS, PARKING.XKRPRMT.XKRPRMT_EXPIRE_YR, PARKING.XKRPRMT.XKRPRMT_TAG FROM PARKING.XKRPRMT WHERE XKRPRMT_PIDM ='" + BannerID + "'");
while (rsTagCheck.next()){
String TagNum = rsTagCheck.getString("XKRPRMT_TAG");
String[] tag = new String[101];
for (int i = 0; i < tag.length; i++)
tag[i] = TagNum;
%>
<table style="border:transparent" style="width:100%">
<tr>
<td style ="width: 300px;">
<select style="width:150px;"tabindex="5" name="Tag">
<option></option><option>T - Temporary</option>
<option><%=tag[0]%></option>
<option><%=tag[1]%></option>
<option><%=tag[2]%></option>
<option><%=tag[3]%></option>
<option><%=tag[4]%></option>
<option><%=tag[5]%></option>
</select>
</td>
</table>
<div style="width:200px;"><input type="submit"value="Add Tag">
</div>
<button onclick="window.location='startup.jsp'">Home</button>
<%}
rsTagCheck.close();
stmt.close();
conn.close();
%>
I NEED HELP
Any help would be greatly appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将 Control Creation 移到 While 循环之外。您的方式是为每个值创建一个新控件。
You need to move the Control Creation outside your While loop. The way you have it a new control is created for each value.
假设您使用 php 并且
$array_from_db
保存您的值,请将其用于您的页面:Assuming you are using php and
$array_from_db
holds your values, use this for your page: