Page 1 of 1

send column data to optionmenu (SOLVED)

Posted: Wed Dec 04, 2013 9:11 pm
by vedus
i will try to make my question simple.
i have a datagrid with data in card-1,and i have 1 option menu into card-3
I need to get the column data from the datagrid (customer_id) of card-1 to the pChosenItem into card-3
i have read the http://lessons.runrev.com/s/lessons/m/d ... -or-column but still is hard to figure out how..
thank you.

Re: send column data to option menu

Posted: Wed Dec 04, 2013 10:19 pm
by Klaus
Hi vedus,
vedus wrote:i will try to make my question simple.
Datagrid questions are rarely simple questions! :D
vedus wrote:i have a datagrid with data in card-1,and i have 1 option menu into card-3
OK, get it.
vedus wrote:I need to get the column data from the datagrid (customer_id) of card-1 to the pChosenItem into card-3
Sorry, don't get this? 8)

You want go get ALL the data from every column named "customer_id" from the datagrid?
Preferrably as a CR delimited list? Is that correct?

And you want to put this into your option button as menuitems?
Is that also correct?

OK, when do you want to do this?
"opencard", "mouseup" etc.?

Basically you need to loop through "the dgdata of grp xyz" and collect all the "customer_id" keys :D
Give some more info and we will solve this!

Best

Klaus

Re: send column data to option menu

Posted: Wed Dec 04, 2013 10:55 pm
by vedus
sorry for the delay..
the datagrid is populate like this
here is the start Up

Code: Select all

on preOpenStack

-- use switch with "the environment" property to determine if the app is running on mobile or in development
   switch the environment

-- if its development, do pretty much what andre was already doing
      case "development"
         -- set default folder
         set the itemdel to "/"
         set the defaultfolder to item 1 to -2 of the effective filename of this stack
         put "databin.sqlite" into tDatabase -- using a variable to store the path to the database file rather than using the path directly in revopendatabase
         break
      case "mobile"
   -- if its mobile, point to where the database should be.
   -- the documents folder is readable and writable.
   -- the engine folder path is only readable.
   -- when the file was included using the "copy files" pane
   -- of the standalone settings, it will end up in the engine folder, next to the executable
   -- but since the engine folder isn't writable you have to copy it to the right place if its not already there.
         put specialfolderpath("documents") & "/databin.sqlite" into tDatabase 

  -- see if the database is already in the documents folder
  -- if not, copy it there from the engine folder
         if there is not a file tDatabase then
            put URL ("binfile:" & specialfolderpath("engine") & "/databin.sqlite") into URL ("binfile:" & tDatabase)
         end if
         break
   end switch

-- since aagDBLib should now be a substack you don't hvae to specify a 
-- path to the file. Just the stack name.
   start using stack "aagDBLib"

-- open the database using the variable tDatabase to point to the file
-- if its on mobile the tdatabase will point to the file in specialfolderpath(documents) 
-- otherwise it will point to a file sitting next to the demo stack.
   get revOpenDatabase("sqlite",tDatabase,,,)

-- catch any errors as andre already did. 
   if it is a number then
      dbSetDefaultConnectionID it
   else
      answer error it
   end if 
end preOpenStack
below code is on card-1 with datagrid

Code: Select all

#Get data from sqlite
put dbGet("customers") into myArray
   set dgdata of control "datagrid" to myArray
then to make the query i use this code.

Code: Select all

#filter the data from sqlite
dbWhere "customer_id","first_name","last_name"
put dbGet("customers") into myRecordsA
Then i want to use the filtered data from dbWhere and use it in the option menu that is on card-3;)

Re: send column data to option menu

Posted: Thu Dec 05, 2013 1:00 pm
by Klaus
Hi vedus,

sorry, no idea how your database library works, what does this mean:
...
dbWhere "customer_id","first_name","last_name"
put dbGet("customers") into myRecordsA
...

And what database field exactly do you want to display in your option menu?
Still don't get it, and unfortunately you did not answer any of my questions! 8)


Best

Klaus

Re: send column data to option menu

Posted: Thu Dec 05, 2013 2:44 pm
by vedus
hi claus
Klaus wrote:Hi vedus,

sorry, no idea how your database library works, what does this mean:
...
dbWhere "customer_id","first_name","last_name"
put dbGet("customers") into myRecordsA
...

And what database field exactly do you want to display in your option menu?
Still don't get it, and unfortunately you did not answer any of my questions! 8)


Best

Klaus
hi Klaus and ty for your patience :)
i use the dblib from Andre for my database.
the dbWhere is the filter query command like this (SELECT * FROM customers WHERE name = 'name';)
and the with dbget i get the whole table.
so with below code i filter my database and i get the "customer_id" from table "customers" as array.

Code: Select all

dbWhere "customer_id"
put dbGet("customers") into myRecordsA
about your questions is

1:) all the data from specific column "customer_id"
2:) i want to put it in the option button as menuitems
3:) i prefer the opencard

Re: send column data to option menu

Posted: Thu Dec 05, 2013 2:51 pm
by Klaus
Hi vedus,
vedus wrote:

Code: Select all

dbWhere "customer_id"
put dbGet("customers") into myRecordsA
aha!

OK, what format is myRecordsA?
All you need is in this variable, but I have no idea if this is an array or a CR delimited list?
vedus wrote:1:) all the data from specific column "customer_id"
2:) i want to put it in the option button as menuitems
3:) i prefer the opencard
Then 3. use an "opencard" handler to fill the button 2.-> set the text of btn "you option menu" to 1. XXX

See above we only need to find out what XXX is and that's it :)


Best

Klaus

Re: send column data to option menu

Posted: Thu Dec 05, 2013 3:04 pm
by vedus
dbGet(tableName) returns a nested array where the first level is a number that will go from 1 to the number of records retrieved. The second level is an array of the field names from the schema and their values.
something like this bellow

Code: Select all

tRecordsA[1]["id"] = 1
tRecordsA[1]["first_name"] = andre
tRecordsA[1]["last_name"] = garzia
tRecordsA[1]["email"] = andre@andregarzia.com

Re: send column data to option menu

Posted: Thu Dec 05, 2013 3:40 pm
by Klaus
OK, given you need all the data from ID, you need to use a repat loop and collect the data:

Code: Select all

...
repeat for each key tKey in tRecordsA
  put tRecordsA[tKey]["id"] & CR after tOptionMenuList
end repeat
## Delete trailing CR
delete char -1 of tOptionMenuList

## Fill option button:
set the text of btn "your option button here..." to tOptionMenuList
...
You get the picture :D

Best

Klaus

Re: send column data to option menu

Posted: Thu Dec 05, 2013 3:51 pm
by vedus
yes now i get it,i will post the results ;)

Re: send column data to option menu

Posted: Thu Dec 05, 2013 5:51 pm
by vedus
here is the solution after klaus help ;)
With dbcolumns i get the columns i want from database file

Code: Select all

  #fill the data
   dbcolumns "first_name,last_name"
   put dbGet("customers") into myRecords
   
   --repeat
  repeat for each key tKey in myRecords
  put myRecords[tKey]["first_name"] & CR after tOptionMenuList
end repeat
## Delete trailing CR
delete char -1 of tOptionMenuList

## Fill option button:
#for unicode text
set the unicodetext of btn "myopt" to uniencode(tOptionMenuList,"utf8")
the above code is working perfect in the option menu.
last question is.
with put myRecords[tKey]["first_name"] & CR after tOptionMenuList we pass the one column from the array
it is possible we pass 2 columns?
i try to put

Code: Select all

repeat for each key tKey in (the keys of myRecords)
  put myRecords[tKey]["first_name"]["last_name"]& CR after tOptionMenuList
but i get empty..

Re: send column data to option menu

Posted: Thu Dec 05, 2013 5:58 pm
by Klaus
Hi vedus,

Code: Select all

repeat for each key tKey in (the keys of myRecords)
put myRecords[tKey]["first_name"]["last_name"]& CR after tOptionMenuList
THAT key "myRecords[tKey]["first_name"]["last_name"]" does not exist! 8)

Do this:

Code: Select all

repeat for each key tKey in (the keys of myRecords)
put myRecords[tKey]["first_name"] && myRecords[tKey]["last_name"]& CR after tOptionMenuList
Best

Klaus

Re: send column data to option menu

Posted: Thu Dec 05, 2013 6:04 pm
by vedus
thank you and really appreciate your help with my code :)
done and the app is working perfect time to deploy it in the ipad ;)