Accessing Table Field Data
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Accessing Table Field Data
Hi.
A friend of mine is helping me build a php page to communicate with my LC stack for registering passwords, email etc. I have parsed a JSON link to one of his php pages and placed the data into a Table Field with 4 lines down and 2 columns across . All I am trying to do is access the second columns that contain the important data. I have tried looking at the rev online lesson about accessing column data in fields but it seems extremely overly complex seeing that you can just put the entire text of the table field into a single field and code access to the lines and characters. So my question is....is there a straight forward way to access the data directly in a table field in any column or line?
Thanks
Bidge
A friend of mine is helping me build a php page to communicate with my LC stack for registering passwords, email etc. I have parsed a JSON link to one of his php pages and placed the data into a Table Field with 4 lines down and 2 columns across . All I am trying to do is access the second columns that contain the important data. I have tried looking at the rev online lesson about accessing column data in fields but it seems extremely overly complex seeing that you can just put the entire text of the table field into a single field and code access to the lines and characters. So my question is....is there a straight forward way to access the data directly in a table field in any column or line?
Thanks
Bidge
Re: Accessing Table Field Data
Hi bidge
You mean a table field right, not a datagrid?
A table field is just a field with a few properties like tabstops set. So if you set the itemDelimiter to tab, you can easily access say 'item 2 of line 4 of field "myTableField"'
You mean a table field right, not a datagrid?
A table field is just a field with a few properties like tabstops set. So if you set the itemDelimiter to tab, you can easily access say 'item 2 of line 4 of field "myTableField"'
Re: Accessing Table Field Data
Hi,
This way?
Have fun!
bidgeeman wrote:[...] the data into a Table Field with 4 lines down and 2 columns across . All I am trying to do is access the second columns that contain the important data. [...]
Code: Select all
set itemdel to tab
get item 2 of line 1 of fld "table_fld"
What I do usually is:bidgeeman wrote:[...] So my question is....is there a straight forward way to access the data directly in a table field in any column or line? [...]
- After retrieving the data (from a file, a database, whatever) I save it for further use. Custom properties is what I prefer for this (I make sure to have proper tab-return delimited data!):
If I need to change the data, I do it in a variable (myData). Often it is useful to have both the actual data & the original data available (for instance to check if the data have changed ...), so I use a second custom property:
Code: Select all
set the cRawData of this stack to myData
Code: Select all
set the cWorkData of this stack to myData
- Sometimes it makes sense to have the data in array form (often I use both forms ...):
Code: Select all
split myData by row set the cRawArray of this stack to myData
- Now that we have the data I can display 'em in the field:
Code: Select all
put the cWorkData of this stack into fld "table_fld"
- This is the easy way - often the data have to be formatted before displaying, so I don't put them into the field directly, but use another custom property, of the field:
and in the field script:
Code: Select all
set the cTableData of fld "table_fld" to myData
So each time I put changed data into my table (via setting the cTableData) the data get nicely formatted (here: column 3 has rounded number), without changing the real data.Code: Select all
setprop cTableData tData repeat for each line myLine in tData put item 1 of myLine & tab & item 2 of myLine & tab & \ round(item 3 of myLine) & CR after myVar end repeat delete last char of myVar put myVar into me pass cTableData end cTableData
- If the user selects a line in the field, and I want to do something based on the content of the 2nd column:
Code: Select all
on selectionChanged -- runs whenever a line is hilited if (line (the hilitedline of me) of me is empty) then exit selectionChanged set itemdel to tab put item 2 of line (the hilitedline of me) of me into myVar -- or wherever end selectionChanged
- Trick: You can save "the tabstops" of your field & change them according to the data you feed to the field. For tabstop management, try "revTabRuler" in Development/Plugins - this is a well hidden gem!
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: Accessing Table Field Data
AxWald.
That worked perfectly thank you so much!
I could only find this online and it totally confused me:
http://lessons.livecode.com/m/datagrid/ ... -or-column
Many thanks once again
Bidge
That worked perfectly thank you so much!
I could only find this online and it totally confused me:
http://lessons.livecode.com/m/datagrid/ ... -or-column
Many thanks once again
Bidge
Re: Accessing Table Field Data
EDIT: [SOLVED] I closed down LC, re-opened it and the error went away????
Sorry to bother you all again but this snippet of code was working well for me earlier but now it has started throwing up and error:
Error Message:
Bidge
Sorry to bother you all again but this snippet of code was working well for me earlier but now it has started throwing up and error:
Code: Select all
on mouseUp
put URL "http://www.something.com" into depthvariable
put jsonimport(depthvariable) into tArray
combine tArray by return and tab
put tArray into field "arraydata"
end mouseUp
Code: Select all
button "Parse": execution error at line 4 (LCB Error in file json.lcb at line 52: syntax error: 1:0 unexpected end of input)
Re: Accessing Table Field Data
Hi,
You can think of the datagrid as a tablefield with attached arrays, scripts, bell, whistles, spoilers & built-in confusion.
Both are doing actually the same, they're just suited for different needs. And have different requirements ...
If you (like me) prefer the lean, fast table field, those links may be helpful for you:
- Scott Rossis "TableLab"
- Bernd Niggemanns "modTableField"
Have fun!
That's about "DataGrids". These are a different beast from table fields.bidgeeman wrote:I could only find this online and it totally confused me:
http://lessons.livecode.com/m/datagrid/ ... -or-column
You can think of the datagrid as a tablefield with attached arrays, scripts, bell, whistles, spoilers & built-in confusion.
Both are doing actually the same, they're just suited for different needs. And have different requirements ...
If you (like me) prefer the lean, fast table field, those links may be helpful for you:
- Scott Rossis "TableLab"
- Bernd Niggemanns "modTableField"
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: Accessing Table Field Data
Hi David,
error checking, error checking, error checking! And "BINFILE"!
You are probably passing invalid data to the "jsonimport()" function.
Best
Klaus
error checking, error checking, error checking! And "BINFILE"!
Code: Select all
on mouseUp
put URL "http://www.something.com" into depthvariable
if the result <> EMPTY then
answer "Error:" && the result
exit to top
end if
put jsonimport(depthvariable) into tArray
combine tArray by return and tab
put tArray into field "arraydata"
end mouseUp
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Accessing Table Field Data
This means the JSON is incorrectly formed. I've seen it many times, usually because there's a missing end bracket or curly brace. It's usually because the PHP script isn't sending the right thing. You will probably see it again if you request the same data as the first time it errored.bidgeeman wrote:EDIT: [SOLVED] I closed down LC, re-opened it and the error went away????
Sorry to bother you all again but this snippet of code was working well for me earlier but now it has started throwing up and error:
It will be difficult to fix without an example of the malformed JSON , so as Klaus said, add some error checking and if one occurs, capture the incoming JSON in a field or text file or somewhere else where you can copy it and show him.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Accessing Table Field Data
Hi Klaus and jacque.
Thank you so much for the error checking pointer. I applied it and no error presented itself?
This is not the first time I have had something strange like that happen though.
Once again thank you for your help.
Bidge
Thank you so much for the error checking pointer. I applied it and no error presented itself?
This is not the first time I have had something strange like that happen though.
Once again thank you for your help.
Bidge
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Accessing Table Field Data
Well, it probably means the error only occurs with some particular types of data retrieval. Leave the error check in place and if it happen again you'll be able to examine the JSON.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com