• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple select box problems

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I'm having problems with a multiple select box in an edit page.
It is a box with categories, and the user may have selected several of the categories when he first registered.
In the edit page, I have problems showing which he already have selected.
My SQL statements:
ResultSet rs3 = stmt3.executeQuery("SELECT * FROM MyCalendarCategories WHERE userid=" + user);
ResultSet rs2 = stmt2.executeQuery("SELECT * from Category ORDER BY catid");
This is how I try to show the selected categories from the MyCalendarCategories table:
<select name="categories" size="8" multiple>
<%
String disp = "";
int val = 0;
boolean cat_test = false;
int catid = 0;
while(rs2.next()){
disp = rs2.getString("category");
val = rs2.getInt("catid");
while(rs3.next()){
catid = rs3.getInt("catid");
if(val == catid){
cat_test = true;
}
}
%>
<%if(cat_test == true){ %>
<option value="<%=val%>" selected> <%=disp%></option>
<%}else{ %>
<option value="<%=val%>"> <%=disp%></option>
<%
}
cat_test = false;
}

Any help appreciated!
regards,
Vidar
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"vlangber",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic