How to set checked Checkbox based on database record?
I would like to raise a question about JSP checkbox
I want to loop the subscription list from the database.
At the same time, I loop the specific user's subscription request.
For example, in the subscription list, there are several items, says
System Analyst
System Developer
System Manager
System Tester
In the subscription list, the user subscrib开发者_运维技巧ed 2 of them, says
System Manager
System Tester
In the looping, I will loop a table with a checkbox column to show all the subscription value.
I encounter a problem here.
I want to make the checkbox "checked" while the user has subscribed the item.
For example, the result of table should have "checked" 2 of the checkbox.
However, I don't know the algorithm to implement my logic.
Can anyone kindly provide some hints for me to realize this?
Thanks.
siris
Coding-
<tr>
<td>Subscription:</td>
<td>
<select name="subscription">
//read the subscription List
ResultSet rs=statement.executeQuery("select * from subsrciption");
//read the user has subscipted what item(s)
ResultSet rs2=statement.executeQuery("select * from request where userid='testing' ");
//in this SQL, for userid-testing, we find 2 records that he subscribed 2 items
//loop the subscription list from database
while ( rs.next() ) {
String subscription = rs.getString("subscription");
//after read the subscription table, how to loop the request table
//while ( rs2.next() ) {
%>
<option value="<%=subscription%>"><%=subscription%></option>
<%
//}
} //end loop subscription list
%>
</select>
</td>
</tr>
You have asked about checkbox in the question and writing for Select in code.
Please edit your post. Use
<INPUT TYPE=CHECKBOX NAME="<%=subscription%>"><%=subscription%>
Secondly,
Get subscription value from rs2
and compare it with rs
精彩评论