in reply to Re: Foreach Loop Optimization
in thread Foreach Loop Optimization

Amazing!! I didn't think of that.

I saved the html output from one of the databases (22 columns and 749 rows) to a local file. When I opened that file in Firefox, it took almost the same time to load as the script on the server!

I gotta clean up my html :(

How can I speed up the browser parsing when I'm not sure how much data and how long the strings of individual fields are going to be?

Replies are listed 'Best First'.
Re^3: OT: Foreach Loop Optimization
by ww (Archbishop) on Aug 01, 2007 at 22:33 UTC

    On the theory this is something you'll have to do repetitively, get the lengths of the longest string in each column (ONCE) to get a ballpark idea of what you need for screen-realestate. Make your peace with a need to sidescroll to see all the columns. And recognize that this is rough and ready; different data sets could make hardcoding this way a total bust (though, of course you could build the length determination function into your program :-) but that could easily overwhelm the speedup.)

    Say the results come up this way:

    col len
    1:   11
    2:   4
    3:   80
    4:   27

    In total, you need space for 122 chars per row plus whatever the row label will be (if used). Let's assume no label. So now you can set up your table this way:

    <table width="100%"> #other good practices omitted; beyond the scope +here <thead> <tr> <th style="width: 11em;">Col1</th> <th style="width: 4em;">Col2</th> <th style="width: 80em;">Col3</th> <th style="width: 27em;">Col4</th> </tr> </thead> <tbody> <tr> <td (whatever styling you want)...</td> etc.

    The tds will inherit their widths from the ths (unless a td ends up with more chars than expected, in which case, different browsers will react in variant ways).

    Hope this helps, but a solid-er answer is probably, "build a better browser."