在经典 ASP 中突出显示特定记录

发布于 2024-11-28 03:32:11 字数 1921 浏览 4 评论 0原文

在我的测验页面中,我有十个问题。当用户浏览这些问题时,我将错误问题的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_蜘蛛 2024-12-05 03:32:11

在我看来,您应该使用循环来确定是否加粗,但不包括循环中的输出。然后使用一个简单的 if 来发送一个输出或另一个输出。

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

Dim bMakeBold
Do While Not rsQuiz.EOF

    bMakeBold = False;
    For  I = LBound(panswer) to UBound(panswer)
        ''# testing whether this question is wrongly answered and if its true then making bold letters.
        If (CStr(rsQuiz.Fields("question_number").Value)) = CStr(panswer(i)) Then
            bMakeBold = True
            Exit For
        End If
    Next

    if bMakeBold then 
        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>")
    else
        response.Write((rsQuiz.Fields("question_number").Value)&") ") 
        response.Write((rsQuiz.Fields("question_text").Value)&"<br>")
        response.Write((rsQuiz.Fields("correct_answer").Value)&"<br>")
    end if

    rsQuiz.MoveNext
Loop
rsQuiz.Close
Set rsQuiz = Nothing
cnnQuiz.Close
Set cnnQuiz = Nothing

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.

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

Dim bMakeBold
Do While Not rsQuiz.EOF

    bMakeBold = False;
    For  I = LBound(panswer) to UBound(panswer)
        ''# testing whether this question is wrongly answered and if its true then making bold letters.
        If (CStr(rsQuiz.Fields("question_number").Value)) = CStr(panswer(i)) Then
            bMakeBold = True
            Exit For
        End If
    Next

    if bMakeBold then 
        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>")
    else
        response.Write((rsQuiz.Fields("question_number").Value)&") ") 
        response.Write((rsQuiz.Fields("question_text").Value)&"<br>")
        response.Write((rsQuiz.Fields("correct_answer").Value)&"<br>")
    end if

    rsQuiz.MoveNext
Loop
rsQuiz.Close
Set rsQuiz = Nothing
cnnQuiz.Close
Set cnnQuiz = Nothing
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文