views:

35

answers:

2

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

A: 

Assuming you are using php and $array_from_db holds your values, use this for your page:

             <select style="width:150px;"tabindex="5" name="Tag">
                 <option></option><option>T - Temporary</option>

<?php
  for( $i=0; $i < count($array_from_db); $i++){
                 echo"<option>".$array_from_db[i]."</option>";
  }
?>
             </select>
Thariama
+2  A: 

You need to move the Control Creation outside your While loop. The way you have it a new control is created for each value.

       <table style="border:transparent" style="width:100%">
            <tr>
             <td style ="width: 300px;">
             <select style="width:150px;"tabindex="5" name="Tag">

<%    while (rsTagCheck.next()){
....
Roadie57