-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathque_sort.jsp
176 lines (174 loc) · 9.54 KB
/
que_sort.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<%--
Document : que_sort
Created on : 2 May, 2022, 5:48:28 PM
Author : hp
--%>
<%@page contentType="text/html" import="java.sql.*" pageEncoding="UTF-8"%>
<%
if(request.getParameter("sort").length()!=0){
String sort = request.getParameter("sort") ;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/stackoverflow","root","");
if(sort.trim().equals("Newest")){
Statement sn1 = cn.createStatement();
ResultSet rs1 = sn1.executeQuery("select * from question where status='0' order by sn asc");
while(rs1.next()){
int ans_count = 0;
Statement sn3 = cn.createStatement();
ResultSet rs3 = sn3.executeQuery("select count(*) from answer where que_code='"+rs1.getString("code")+"'");
if(rs3.next()){
ans_count = Integer.parseInt(rs3.getString("count(*)"));
}
int count_view = 0;
Statement sn4 = cn.createStatement();
ResultSet rs4 = sn4.executeQuery("select count(*) from user_view where que_code='"+rs1.getString("code")+"'");
if(rs4.next()){
count_view = Integer.parseInt(rs4.getString("count(*)"));
}
int count_vote = 0;
Statement sn5 = cn.createStatement();
ResultSet rs5 = sn5.executeQuery("select count(*) from vote where que_code='"+rs1.getString("code")+"'");
if(rs5.next()){
count_vote = Integer.parseInt(rs5.getString("count(*)"));
}
%>
<div class="col-sm-12" style="border-bottom: 0.5px ridge wheat;border-top: 0.5px ridge wheat;">
<div class="row" style="padding:10px;">
<div class="col-sm-1">
<table class="tabel " cellpadding="5px">
<tr><td style="float:right;padding: 5px;"> <%=count_vote%> votes </td></tr>
<tr><td style="float:right;padding: 5px;"> <%=ans_count%> answer </td></tr>
<tr><td style="float:right;padding: 5px;"> <%=count_view%> views </td></tr>
</table>
</div>
<div class="col-sm-9">
<table class="tabel" cellpadding="5px">
<tr>
<td><a href="answer.jsp?code=<%=rs1.getString("code")%>" style="font-size: 20px;padding-left:10px;text-decoration:none;"><%=rs1.getString("title")%></a></td>
</tr>
<tr>
<td style="padding-left:15px;">
<%
String s[] = rs1.getString("tags").split(",");
for(int i=0;i<s.length;i++){
%>
<button class="w3-button w3-tiny w3-round" style="background-color: #ADD8E6;"><%=s[i]%></button>
<%
}
%>
</td>
</tr>
</table>
</div>
<div class="col-sm-2">
<%
String que_date[] = rs1.getString("date").split("at");
String from_email = rs1.getString("from_email");
Statement sn2 = cn.createStatement();
ResultSet rs2 = sn2.executeQuery("select * from user where email='"+from_email+"'");
if(rs2.next()){
%>
<table class="tabel" cellpadding="5px">
<tr>
<img src="users/<%=rs2.getString("code")%>.jpg" style="width: 30px;height: 30px;" class="img-fluid rounded">
<%=rs2.getString("username")%>
</tr>
<tr><td style="padding-top: 10px"><%=que_date[0]%></td></tr>
<tr><td style="padding-top: 10px"><%=que_date[1]%></td></tr>
</table>
<%
}
%>
</div>
</div>
</div>
<%
}
}
else if(sort.trim().equals("Oldest")){
Statement sn1 = cn.createStatement();
ResultSet rs1 = sn1.executeQuery("select * from question where status='0' order by sn desc");
while(rs1.next()){
int ans_count = 0;
Statement sn3 = cn.createStatement();
ResultSet rs3 = sn3.executeQuery("select count(*) from answer where que_code='"+rs1.getString("code")+"'");
if(rs3.next()){
ans_count = Integer.parseInt(rs3.getString("count(*)"));
}
int count_view = 0;
Statement sn4 = cn.createStatement();
ResultSet rs4 = sn4.executeQuery("select count(*) from user_view where que_code='"+rs1.getString("code")+"'");
if(rs4.next()){
count_view = Integer.parseInt(rs4.getString("count(*)"));
}
int count_vote = 0;
Statement sn5 = cn.createStatement();
ResultSet rs5 = sn5.executeQuery("select count(*) from vote where que_code='"+rs1.getString("code")+"'");
if(rs5.next()){
count_vote = Integer.parseInt(rs5.getString("count(*)"));
}
%>
<div class="col-sm-12" style="border-bottom: 0.5px ridge wheat;border-top: 0.5px ridge wheat;">
<div class="row" style="padding:10px;">
<div class="col-sm-1">
<table class="tabel " cellpadding="5px">
<tr><td style="float:right;padding: 5px;"> <%=count_vote%> votes </td></tr>
<tr><td style="float:right;padding: 5px;"> <%=ans_count%> answer </td></tr>
<tr><td style="float:right;padding: 5px;"> <%=count_view%> views </td></tr>
</table>
</div>
<div class="col-sm-9">
<table class="tabel" cellpadding="5px">
<tr>
<td><a href="answer.jsp?code=<%=rs1.getString("code")%>" style="font-size: 20px;padding-left:10px;text-decoration:none;"><%=rs1.getString("title")%></a></td>
</tr>
<tr>
<td style="padding-left:15px;">
<%
String s[] = rs1.getString("tags").split(",");
for(int i=0;i<s.length;i++){
%>
<button class="w3-button w3-tiny w3-round" style="background-color: #ADD8E6;"><%=s[i]%></button>
<%
}
%>
</td>
</tr>
</table>
</div>
<div class="col-sm-2">
<%
String que_date[] = rs1.getString("date").split("at");
String from_email = rs1.getString("from_email");
Statement sn2 = cn.createStatement();
ResultSet rs2 = sn2.executeQuery("select * from user where email='"+from_email+"'");
if(rs2.next()){
%>
<table class="tabel" cellpadding="5px">
<tr>
<img src="users/<%=rs2.getString("code")%>.jpg" style="width: 30px;height: 30px;" class="img-fluid rounded">
<%=rs2.getString("username")%>
</tr>
<tr><td style="padding-top: 10px"><%=que_date[0]%></td></tr>
<tr><td style="padding-top: 10px"><%=que_date[1]%></td></tr>
</table>
<%
}
%>
</div>
</div>
</div>
<%
}
}
cn.close();
}
catch(ClassNotFoundException e){
System.out.println("Driver : "+ e.getMessage());
}
catch(SQLException ec){
System.out.println("SQL : "+ec.getMessage());
}
}
%>