Current location: Hot Scripts Forums » Programming Languages » ASP » Nested loop problems...


Nested loop problems...

Reply
  #1 (permalink)  
Old 12-18-07, 08:34 AM
invision invision is offline
Newbie Coder
 
Join Date: Dec 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Spin Nested loop problems...

Sorry, wrong subject title.

I wish to use a Do...While loop to echo out results from a SQL query to my database.

PHP Code:

    Dim cn,sql,Rs
                Set cn 
Server.CreateObject("ADODB.Connection")
                
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Server.MapPath("../../database/TESTER.mdb") &";Persist Security Info=False"
  
                
sql "SELECT * FROM clients WHERE status = 1"
                
    
    
WHILE LOOP
    
                response
.write ('<option val="uid"> client_name </option>')
                
    
END WHILE LOOP
    
    
&#37;> 
What is the best way to do this?

Last edited by invision; 12-18-07 at 08:48 AM.
Reply With Quote
  #2 (permalink)  
Old 12-18-07, 08:40 AM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
seems like a typo - what's on line 17?
__________________
"Political Correctness is a doctrine, fostered by a delusionary, illogical, liberal minority and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end."
Reply With Quote
  #3 (permalink)  
Old 12-18-07, 08:50 AM
invision invision is offline
Newbie Coder
 
Join Date: Dec 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Oops, sorry about that. I posted up the wrong script. Too many things in my clipboard

I'm trying to use a while loop to echo out entries from my table into option values for a select menu.

Is there an easy way to do this?
Reply With Quote
  #4 (permalink)  
Old 12-18-07, 09:03 AM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
X_X

asp Code:
  1. If Not Rs.EOF Then
  2.    Response.Write("<select id='blahblah'>")
  3. End If
  4.  
  5. Do while not Rs.EOF
  6.    Response.Write "<option value = '" & RS ("uid") & "'> & Rs("client_name") & "</option>""
  7.    Rs.MoveNext
  8.    If Rs.EOF Then
  9.       Response.Write("</select>")
  10.    End If
  11. Loop
__________________
"Political Correctness is a doctrine, fostered by a delusionary, illogical, liberal minority and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end."
Reply With Quote
  #5 (permalink)  
Old 12-18-07, 09:17 AM
invision invision is offline
Newbie Coder
 
Join Date: Dec 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the fast response.

I've tried putting the code in, but got an error:
Code:
Microsoft VBScript compilation  error '800a0401'

Expected end of statement

/client_space/add_project.asp, line 56

Response.Write "<option value = '" & RS ("uid") & "'> & Rs("client_name") & "</option>""
------------------------------------------------------------^
Reply With Quote
  #6 (permalink)  
Old 12-18-07, 09:23 AM
omniman's Avatar
omniman omniman is offline
Coding Addict
 
Join Date: Aug 2006
Location: Baltimore, MD
Posts: 342
Thanks: 0
Thanked 1 Time in 1 Post
It's a problem with the quotes, that's all - figure it out.
__________________
"Political Correctness is a doctrine, fostered by a delusionary, illogical, liberal minority and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a turd by the clean end."
Reply With Quote
  #7 (permalink)  
Old 12-18-07, 09:39 AM
invision invision is offline
Newbie Coder
 
Join Date: Dec 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Do I have to cancel out the quotes around the Rs("client_name") or just use singles?

Sorry to be such a noob to ASP
Reply With Quote
  #8 (permalink)  
Old 12-18-07, 10:21 AM
invision invision is offline
Newbie Coder
 
Join Date: Dec 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
OK, so I now have:
PHP Code:

    <%

                
Set cn Server.CreateObject("ADODB.Connection")
                
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Server.MapPath("../../database/HIDDEN/db.mdb") &";Persist Security Info=False"
  
                
sql "SELECT * FROM clients WHERE status = 1"
                
If Not Rs.EOF Then
   Response
.Write("<select id='client'>")
End If

Do while 
not Rs.EOF
   Response
.Write "<option value = """ Rs ("uid") & """>" Rs("client_name") & "</option>"
   
Rs.MoveNext
   
If Rs.EOF Then
      Response
.Write("</select>")
   
End If
Loop
    
%> 
and I get the following HTML output:
HTML Code:
  <p><strong>Username:</strong> <br /><select name="client">
	
	 <font face="Arial" size=2>
<p>Microsoft VBScript runtime </font> <font face="Arial" size=2>error '800a01a8'</font>

<p>
<font face="Arial" size=2>Object required: ''</font>
<p>
<font face="Arial" size=2>/client_space/add_project.asp</font><font face="Arial" size=2>, line 51</font> 
Any assistance would be brilliant at this point. I'm stuck for ideas I'm afraid.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
infinite loop versus guarded blocks UnrealEd Everything Java 0 11-11-07 02:53 PM
Update multiple rows outside loop - need help ElvansX PHP 1 12-03-06 01:55 AM
While loop jaishalg PHP 1 11-23-04 03:36 PM
loop problems taydag PHP 0 01-27-04 03:33 AM
type mismatch and update loop - HELP! seala ASP 1 09-22-03 05:27 PM


All times are GMT -5. The time now is 04:00 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.