I am trying to create a display of multiple levels of membership, and wondered about the pros and cons of doing recursive DB queries vs. drawing in all data in a single query, and then developing a means of manipulating the data in the array into a format that would be presentable?
My thoughts are that the less you have to hit the DB, the better off you will be performance wise, but then if you consider that the membership has the potential to grow into the 10's of thousands or more, is it unreasonable to think that all that data could be manipulated efficiently from a single array?
The query is simple and only gets 4 fields
ref_id, mem_id, username, status
What I want to do is show a sort of family tree for the first 3 levels, and then basically for each member on level 3, show a count of the people on all the remaining levels that are in their downline
Does this sound like something that could be managed with a single query and manipulating the data in a single array?
I've generated sample data inserts into a table users and did a line item display of the data to view the results. The mem_id was auto incremented, and the ref_id was randomly selected from all available mem_id's, pushing each new one as it was created onto the array. This was the best way I could figure to come up with a random sampling, as if it were real life membership data.
I was thinking that I could possibly create an array for each of the levels 1, 2, and 3, that would contain only the mem_id and the corresponding ref_id, and then display the data by using 3 levels of embedded loops, but I don't know how to go about getting the count for the balance of the records that are related to each of the 3rd level records.
I hope this isn't too confusing. The more I type, the more I question what I am doing...
Any suggestions would be greatly appreciated, especially if I am heading down a road that I shouldn't be on.
thanks in advance for your feedback.
Doug
BTW, here is the table of data that I generated starting with mem101, and the L1 members are referred by 101, the L2 members referred by the previous L1, i.e. 106 referred 107, 123, 126, and 174, etc.
[pre]start L1 L2 L3 L4 L5 L6
101 103
104
106 107 114 142 146 171
197
120 143 188
205
124 135
136 152 161
193
198
123 138
194
126 154
174 190
108 110 113 160 191
116 102
117 122 158
130 145
184
162
148 187
139
144 186
195
109 112 134 165 168
181
115 121
127 175 189
132 157 169
156 204
179 185
111 170
118 125 164 192
133 147 155 183
141 182
201
119 129 131 200
153 196
203
173 177 180
137 163
151 199
159
166 167
172
128 140 150
149
176
178[/pre]