在经典 ASP 中突出显示特定记录
在我的测验页面中,我有十个问题。当用户浏览这些问题时,我将错误问题的 ID 存储在一个数组中。当用户单击“显示结果”链接时,我将显示所有 10 个问题及其答案。我想用粗体字母突出显示错误回答的问题。
这是我的代码:
Dim DB_CONN_STRING
DB_CONN_STRING = "DBQ=" & Server.MapPath("quiz.mdb") & ";"
DB_CONN_STRING = DB_CONN_STRING & "Driver={Microsoft Access Driver (*.mdb)};"
DB_CONN_STRING = DB_CONN_STRING & "DriverId=25;FIL=MS Access;"
Const QUIZ_ID = 1
Dim panswer
panswer=split((Request.QueryString("marked")),",")
''# collecting wrongly answered question id in panswer
Dim cnnQuiz, rsQuiz, I
Set cnnQuiz = Server.CreateObject("ADODB.Connection")
cnnQuiz.Open DB_CONN_STRING
Set rsQuiz = Server.CreateObject("ADODB.Recordset")
rsQuiz.Open "SELECT * FROM questions WHERE quiz_id=" & QUIZ_ID & " ORDER BY question_number;", cnnQuiz, 3, 1
Do While Not rsQuiz.EOF
For I = LBound(panswer) to UBound(panswer)
if (CStr(rsQuiz.Fields("question_number").Value)) = CStr(panswer(i)) then
''# testing whether this question is wrongly answered and if its true then making bold letters.
response.Write("<b>"&(rsQuiz.Fields("question_number").Value)&")</b>")
response.Write("<b>"&(rsQuiz.Fields("question_text").Value)&"</b><br>")
response.Write("<b>"&(rsQuiz.Fields("correct_answer").Value)&"</b><br>")
end if
Next
'' # else displaying all 10 questions
response.Write((rsQuiz.Fields("question_number").Value)&") ")
response.Write((rsQuiz.Fields("question_text").Value)&"<br>")
response.Write((rsQuiz.Fields("correct_answer").Value)&"<br>")
rsQuiz.MoveNext
Loop
rsQuiz.Close
Set rsQuiz = Nothing
cnnQuiz.Close
Set cnnQuiz = Nothing
问题:此代码显示所有 10 条记录,但只有数组中的第一项突出显示,并且重复两次。这是一个现有的网站,我必须保留经典 ASP。
In my quiz page, I have ten questions. When the user goes through these questions, I store the IDs of wrong questions in a array. When the user clicks on the "show result" link, I'm going to display all 10 questions with their answers. I want to highlight wrongly answered question with bold letters.
Here's my code:
Dim DB_CONN_STRING
DB_CONN_STRING = "DBQ=" & Server.MapPath("quiz.mdb") & ";"
DB_CONN_STRING = DB_CONN_STRING & "Driver={Microsoft Access Driver (*.mdb)};"
DB_CONN_STRING = DB_CONN_STRING & "DriverId=25;FIL=MS Access;"
Const QUIZ_ID = 1
Dim panswer
panswer=split((Request.QueryString("marked")),",")
''# collecting wrongly answered question id in panswer
Dim cnnQuiz, rsQuiz, I
Set cnnQuiz = Server.CreateObject("ADODB.Connection")
cnnQuiz.Open DB_CONN_STRING
Set rsQuiz = Server.CreateObject("ADODB.Recordset")
rsQuiz.Open "SELECT * FROM questions WHERE quiz_id=" & QUIZ_ID & " ORDER BY question_number;", cnnQuiz, 3, 1
Do While Not rsQuiz.EOF
For I = LBound(panswer) to UBound(panswer)
if (CStr(rsQuiz.Fields("question_number").Value)) = CStr(panswer(i)) then
''# testing whether this question is wrongly answered and if its true then making bold letters.
response.Write("<b>"&(rsQuiz.Fields("question_number").Value)&")</b>")
response.Write("<b>"&(rsQuiz.Fields("question_text").Value)&"</b><br>")
response.Write("<b>"&(rsQuiz.Fields("correct_answer").Value)&"</b><br>")
end if
Next
'' # else displaying all 10 questions
response.Write((rsQuiz.Fields("question_number").Value)&") ")
response.Write((rsQuiz.Fields("question_text").Value)&"<br>")
response.Write((rsQuiz.Fields("correct_answer").Value)&"<br>")
rsQuiz.MoveNext
Loop
rsQuiz.Close
Set rsQuiz = Nothing
cnnQuiz.Close
Set cnnQuiz = Nothing
Problem: this code displays all 10 records, but only the first item in the array gets highlighted, and it repeats twice. This is an existing website and I have to keep to classic ASP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您应该使用循环来确定是否加粗,但不包括循环中的输出。然后使用一个简单的 if 来发送一个输出或另一个输出。
Looks to me like you should be using the loop to determine whether the make bold or not but not include output in the loop. Then use a simple if to send one output or the other.