data from query into scrolling list field

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

data from query into scrolling list field

Post by francof » Sun Jun 29, 2014 6:24 pm

Hi again with another question.

as in subject, I'm trying to show item 1 of all the lines of data from query into a scrolling list field.
the data back from query are 2 items, column "DOMANDA" and column "RISPOSTA"
I only am able to show all the 2 items so:

Code: Select all

set ItemDel to TAB
    put tRsTrovaDom  into field "txtDomTrovate"  
in this way:

Code: Select all

set ItemDel to TAB
    put item 1 of tRsTrovaDom  into field "txtDomTrovate"  
I've back only item 1 (column DOMANDA) but, only of the first line...

another try:

Code: Select all

 repeat for each line i in tRsTrovaDom
      put item 1 of line i of tRsTrovaDom  into field "txtDomTrovate"      -- item 1 contiene la domanda
   end repeat
stops with error:
"card "crdDomAperte": execution error at line 93 (Chunk: error in range start expression), char 1"

thanks for help
franco

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: data from query into scrolling list field

Post by bangkok » Sun Jun 29, 2014 6:35 pm

francof wrote:

Code: Select all

 repeat for each line i in tRsTrovaDom
      put item 1 of line i of tRsTrovaDom  into field "txtDomTrovate"      -- item 1 contiene la domanda
   end repeat
stops with error:
franco
You mixed up repeat for each and repeat with

Code: Select all

repeat for each line tLine in tRsTrovaDom
      put item 1 of tLine  after field "txtDomTrovate"    
   end repeat
Or

Code: Select all

repeat with i = 1 to the number of lines of tRsTrovaDom
      put item 1 of line i of tRsTrovaDom  after  field "txtDomTrovate"    
   end repeat
By the way, watchout with "into" for a field within a loop.... It doesn't make sense (the content of the field will be replaced at each iteration of the loop).

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: data from query into scrolling list field

Post by phaworth » Sun Jun 29, 2014 7:49 pm

Should be:

put item 1 of line i of tRsTrovaDom & return after field "txtDomTrovate"

... assuming each item is to be on a separate line.

Pete

francof
Posts: 237
Joined: Fri Apr 11, 2014 10:51 am

Re: data from query into scrolling list field

Post by francof » Sun Jun 29, 2014 8:45 pm

Hi bangkok, Pete
I solved merging your answer both...

Code: Select all

set ItemDel to TAB
    repeat for each line tLine in tRsTrovaDom
      put item 1 of tLine  & return after field "txtDomTrovate"   
   end repeat
just one thing wrong:
I think to have in the column "RISPOSTA",in the table of the DB, some data divided in 2 or more lines. so I've a part of "RISPOSTA"(which should be ITEM 2) like ITEM 1, and show in the field "txtDomTrovate" reserved to the item1 "DOMANDE"
sorry I've forgot to clarify.... (DOMANDE mean questions, and RISPOSTA mean answer)
bangkok wrote: ...............
By the way, watchout with "into" for a field within a loop.... It doesn't make sense (the content of the field will be replaced at each iteration of the loop).
and how can I do in a better way?
in my case I haven't a lot of iterations but, in case of hundreds or thousand of them..... could be not the best.

ciao and thanks all
franco

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: data from query into scrolling list field

Post by MaxV » Wed Jul 09, 2014 11:51 am

Here the problem is how you obtain the data from the DB, because your answers contain return char.
Example, if you dB is:

Code: Select all

|DOMANDA | RISPOSTA |
|--------+----------|
|1+1?    | 2        |
|--------+----------|
|names?  |Ale and   |
|        |Max       |
|--------+----------|
when you retrieve data with this code:

Code: Select all

put revDataFromQuery(tab,return,connID,tSQL) into tRecords
You obtain:

Code: Select all

1+1?    2
name?   Ale and
Max
You have to change the line separator char, for example with:

Code: Select all

put revDataFromQuery("+++","%%%",connID,tSQL) into tRecords
you get:

Code: Select all

1+1?+++2%%%name?+++Ale and
Max
This way you can separate values without problem with return char.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: data from query into scrolling list field

Post by Klaus » Wed Jul 09, 2014 11:57 am

Hi Max,

looks like this has been solved in another thread:
http://forums.livecode.com/viewtopic.php?f=12&t=20946


Best

Klaus

Post Reply