• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Multiple select box problems

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic