This is for the Wizards of Arrays among you.

All these years I’ve done most of my list processing with “repeat for each line 
x of some list”
Where the lines are tab delimited data  or | pipe delimited. My baby talk 
stepping through these and parsing for items on the way thru works. It’s also 
very easy to read and plenty fast enough even if you get to 10,000 plus lines.. 
 Slowly I’m getting to grips with arrays and using them whenever I can wrap my 
head around the algorithm. My current use case has me stumped. The number of 
lines of the list is small, and I could use my old parsing methods but I would 
like to see how arrays might be used to better effect. I’m sure this has been 
addressed many times by the Wizards of the Arrays

More and more we are accessing web databases where the significant data is in a 
relational table.

E. g.  table categories:  category_id | name

category_tree   parent_id | child_id

I see these little “mysterious” relational tables everywhere.. In Word Press, 
XOOPS modules etc. I say mysterious because they often consist of just two 
columns with the primary ID’s from one or two other tables.

The core of the challenge lies in the fact that if you take the first item as a 
“key” it won’t work because  it may be used multiple times and if you just 
split by cr and tab… something like the following:

Eg (tab separated here]

Categories

138  Fruit
107  Vegetables
111  Dead Animals
43   Apples

Etc

Category tree: this is the relational table:


12      6
138     43
107     139
99      6
88      134
26      6
55      6
108     6
81      2
63      6
138     131
130     131
45      6
91      131
37      6
75      139
107     131
127     131
11      131
138     6
111     106

Etc.  means you will end up with aCategoryParents[“138”]  = 6  when in fact 
there are three “children” of parent ID 138 in the list. So you cannot really 
set “138” as a key because it has multiple values that need to be addressed and 
parseable.  Now I know I could go diving into the world of SQL queries and get 
the server API’s to run those against the database, but I want to reduce the 
server side processing requirements/connections for the client side app and we 
may even store this in customProps so they are accessible off line and the 
simplest thing, server side, is to just get the API to dump the tables to tab 
delimited lists and ship that to the client… These lists are small -- 130 to 
500 lines at most. Select * from table is nearly instantaneous…   Then do the 
work with LC list tools and arrays. This keeps my API’s simple and keeps the 
app code with the app.  What I want to able to do is quickly shift between data 
sets like this

Parent  | Children
138     | 43,131,6

The user will be clicking on the human readable Parent lists like

Fruit
Vegetables
Dead Animals

They click on the list on the left and on the right show, e.g. 

 Fruit      apples
            Pears
            Grapes

Then 

Dead Animals   Pork chops
               Salmon
               Chicken

I wonder how this might be facilitated with arrays? But I can’t wrap my head 
around the core problem: how to split a list where the first element may be 
repeated throughout with different values. And if there is a way…with nested 
arrays... how to query that array to get the data back out?

OK… I’m off to write my old methods… for now..
 
repeat for each line x in tParentChildList
   # parse and output the items here… usually takes a number of lines, 
   # setting flags and little local vars along the way
End repeat  

It will be interesting if these introduce delays in the UI. I’m sure that 
arrays is probably a better way to go…but beyond me…if this is something you 
have solved. Can you share?

Thanks!

BR
               
   
            







_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to