This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic