Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 17th, 2006, 01:05 PM
rmillz rmillz is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 2 rmillz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 41 sec
Reputation Power: 0
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'>&nbsp</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
%>

Reply With Quote
  #2  
Old May 17th, 2006, 01:26 PM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
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



Reply With Quote
  #3  
Old May 17th, 2006, 01:36 PM
rmillz rmillz is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 2 rmillz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 41 sec
Reputation Power: 0
Quote:
Originally Posted by nofriends
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


I appreciate you making my first post a successful one! It did filter out the multiple entries. Thanks again!

Reply With Quote
  #4  
Old May 17th, 2006, 01:47 PM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1Folding Points: 112786 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
no problem, glad it worked

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Looping error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT