Page 1 of 1

Database Loop

Posted: Sat Jun 25, 2011 7:42 pm
by jesse
I am trying to construct a repeat loop that can loop through my database results but I'm not sure how to get
the data in the loop. Here is what I have so far.

This appears to return the id of the query livecode has assigned it. but from there i'm not sure how to get the data.

Code: Select all

   put revQueryDatabase(conID,tSQL) into tCursor
put revDataFromQuery(tab,return,conID,tSQL) into tRecords
then i have my repeat loop which was using revDataFromQuery but I can't refer to the columns by name using revDataFromQuery
so its my understanding I need to change over to using revDataFromQuery to revQueryDatabase but I can't seem to find any
examples using it in a repeat loop so I'm not sure how to actually loop the data and refer to the columns in the loop.

Code: Select all

     repeat with i = 1 to the number of lines of tRecords
        answer line i of tRecords
end repeat
Once again if anyone can come to my rescue that would be great!

Re: Database Loop

Posted: Sat Jun 25, 2011 8:04 pm
by dglass
Since you have cursor/recordset (tCursor) your loop would look like this:

Code: Select all

repeat until revQueryIsAtEnd(tCursor)

....do whatever you need to do with the current record           

revMoveToNextRecord tCursor
end repeat

Re: Database Loop

Posted: Sun Jun 26, 2011 1:15 am
by jesse
thank you again. your really great help!