|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Looping error
I am trying to self-learn asp and SQL using VB... below is a code snipet of where I am having the problem... apparently my code is looping too many times... any suggestions are appreciated including alternative ways to accomplish the same results... thank you in advance...
my current output looks like this: 1 What is your favorite color? Black Yellow Orange Black Yellow Orange Black Yellow Orange Black Yellow Orange 2 Which of these animals are you favorite? Bear Cat Bear Cat Bear Cat Bear Cat I want it to look like this: 1 What is your favorite color? Black Yellow Orange 2 Which of these animals are you favorite? Bear Cat here is the code thus far: Code:
<html>
...
<%
'establish a connection with the database
accessDB = "GuestLog.mdb"
DSNStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath(accessDB) & ";"
set Conn = Server.CreateObject("ADODB.Connection")
Conn.open DSNStr
%>
...
<%
SQL = "SELECT * FROM surveyquestions"
'recordset of questions
Set ques_rs = Server.CreateObject("ADODB.Recordset")
ques_rs.open SQL, Conn
'recordset of answers
Set ans_rs = Server.CreateObject("ADODB.Recordset")
Response.Write("<table><tr height='100px'> </tr>")
While Not ques_rs.EOF
Response.Write("<tr><td align='right' width='30%'>" & ques_rs("questionID") & "</td>")
Response.Write("<td>" & ques_rs("question") & "</td></tr>")
'making another record set for answers
SQL = "SELECT surveryanswers.answers FROM surveyanswers,surveyquestions WHERE surveyanswers.questionID="&ques_rs("questionID")
ans_rs.open SQL, Conn
While Not ans_rs.EOF
Response.Write("<tr><td></td><td align='right'>" & ans_rs("answer") & "</td></tr>")
ans_rs.MoveNext
WEnd
ans_rs.close
ques_rs.MoveNext
WEnd
Response.Write("</table>")
'close the recordset
ques_rs.close
'close the database connection
conn.close
%>
|
|
#2
|
||||
|
||||
|
Hi and welcome to the forum
![]() your loop looks good to me, try changing the sql to only select DISTINCT values, there might be duplicates in your table itself Code:
'making another record set for answers
SQL = "SELECT DISTINCT surveryanswers.answers FROM surveyanswers,surveyquestions WHERE surveyanswers.questionID="&ques_rs("questionID")
ans_rs.open SQL, Conn
hope this helps
__________________
Look! Its a ShemZilla ![]() ![]()
|
|
#3
|
|||
|
|||
|
Quote:
I appreciate you making my first post a successful one! It did filter out the multiple entries. Thanks again! |
|
#4
|
||||
|
||||
|
no problem, glad it worked
![]() |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Looping error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|