Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Belmyrddyn
Magician


Joined: 17 Oct 2001
Posts: 371
Location: USA

PostPosted: Tue Mar 04, 2003 12:00 am   

ADO Database Loop
 
Okay, this bit of script is designed to retrieve all of the 'Friends' (stored in an ADO database) that the character I'm connected to has stored. It saves it into 10 different string lists, depending on what color I want the Friend's name to be highlighted. @Friends1 - @Friends10.
Now, for the most part this script works, however the first item of each stringlist is the name of the stringlist itself, which I'm at a total loss to understand why. Second, it only loads 1 name from each color code, no matter how many entries are in the database.

#VAR SQL %concat( %char( 34), "SELECT * FROM [tblFriends] WHERE [Name] = ~'", %item( @Character, 1), "~' ORDER BY [Color Code]", %char( 34))
#CALL @DBConnection.Open( @SQL, @ConnStr, 2, 2)
#IF ((@DBConnection.bof) AND (@DBConnection.eof)) {#CALL @DBConnection.Close} {
#CALL @DBConnection.MoveFirst
#LOOP 10 {
#IF (@DBConnection.eof) {#ABORT}
#VAR Temp %i
#WHILE (%int( @DBConnection( "Color Code")) = %i) {
#IF (@DBConnection.eof) {#ABORT}
#VAR %concat( "Friends", @Temp) %additem( @DBConnection( "First Name"), %concat( "Friends", @Temp))
#CALL @DBConnection.MoveNext
}
}
}
#CALL @DBConnection.Close

The SQL statement works, so you don't need to check that.

Belmyrddyn
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Mar 04, 2003 3:15 am   
 
The problem is in the %additem. Instead of saving the counter to a temporary variable, use the %i directly, like this:
#VAR Friends%i %additem(@DBConnection("First Name), @{Friends%i})

Kjata
Reply with quote
Belmyrddyn
Magician


Joined: 17 Oct 2001
Posts: 371
Location: USA

PostPosted: Tue Mar 04, 2003 3:33 am   
 
Can you do that in a sub-loop structure? I assumed %i would be taken over by the #WHILE structure, but I want the %i of the #LOOP structure.

EDIT: Okay, just implemented it, and it works like a CHARM. Thanks so much, Kjata, I had spent forever banging my head with this one.

Belmyrddyn
Reply with quote
Belmyrddyn
Magician


Joined: 17 Oct 2001
Posts: 371
Location: USA

PostPosted: Tue Mar 04, 2003 4:17 am   
 
In conjunction with this... is there a variable which has the number of times the #WHILE structure had repeated?

Belmyrddyn
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Mar 04, 2003 5:05 am   
 
Nope, you need to maintain your own counter for that.

Kjata
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net