[thelist] denormalizing a result set in dreamweaver

r937 rudy at r937.com
Fri Feb 8 10:47:35 CST 2008


i ended up advising my client to modify his php

(not sure if he can do it, but his php skills are guaranteed better than 
mine, as mine are zero)

recap:  the query produces a sorted one-to-many result set --

   foo  aa 9
   foo  bb 3
   foo  cc 7
   bar  xx 4
   qux  mm 5
   qux  nn 7
   qux  oo 8

he originally asked me to try to produce a query result set with only one 
row per location --

   foo  aa 9  bb 3  cc 7
   bar  xx 4
   qux  mm 5  nn 7  oo 8

but this is insanely difficult to do with sql

right now he's (already) doing the following with his php (my pseudocode) --

. run the query
. while rows remaining, get next result row
     process the result row
. end while

i advised him to rewrite it like this --

. run the query
. set $prevlocation = '' /* empty string */
. while rows remaining, get next result row
     if result row location = $prevlocation
          append row data to end of array (or whatever)
     else /* new location, process previous location first */
          if $prevlocation > ''  /* i.e. not first time though */
             process $prevlocation with all appended data
          endif
          set $prevlocation = current result row location
     endif
. end while
. process $prevlocation with all appended data
   ( for the last location )


this'll work, yeah?



rudy 





More information about the thelist mailing list