School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,314 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,058 people online right now. Registration is fast and FREE... Join Now!




Lists - Less looping for a little faster performance?

 

Lists - Less looping for a little faster performance?, alliteration aside, any thoughts?

armyCoder

21 May, 2009 - 01:20 PM
Post #1

D.I.C Head
**

Joined: 2 Feb, 2009
Posts: 54



Thanked: 1 times
My Contributions
Almost the weekend! I'm working on a personnel project and part of the data is education related. I have a database of 3100+ universities. There are 6 drop down lists under the education tab representing a maximum of 6 degrees each user may have attained. Some only have 1...and only one has 6...but they want 6 drop down boxes...just in case. Well each drop down loops this 3100+ database and lists it. I'm on fiber lan on the same switch as the server and it still takes 3 seconds to load the page. Is there a better way to maybe loop through everything once, store it somehow and display it? Here's my code now.

CODE

<label>
                  <select name="school_1" id="school_1">
<option value="#getdata.school_1#" selected="selected">#getschools.school_1#</option>
<cfloop query="getallschools"><option value="#getallschools.sch_code#">#school#</option></cfloop>
                  </select>
                </label>
             </td>
          
              <td>2:</td>
              <td><select name="school_2" id="school_2">
                <option value="#getdata.school_2#" selected="selected">#getschools.school_2#</option>
                <cfloop query="getallschools">
                  <option value="#getallschools.sch_code#">#school#</option>
                </cfloop>
              </select></td>
            
              <td>3:</td>
              <td><select name="school_3" id="school_3">
                <option value="#getdata.school_3#" selected="selected">#getschools.school_3#</option>
                <cfloop query="getallschools">
                  <option value="#getallschools.sch_code#">#school#</option>
                </cfloop>
              </select></td>
            

              <td>4:</td>
              <td><select name="school_4" id="school_4">
                <option value="#getdata.school_4#" selected="selected">#getschools.school_4#</option>
                <cfloop query="getallschools">
                  <option value="#getallschools.sch_code#">#school#</option>
                </cfloop>
              </select></td>
            
              <td>5:</td>
              <td><select name="school_5" id="school_5">
                <option value="#getdata.school_5#" selected="selected">#getschools.school_5#</option>
                <cfloop query="getallschools">
                  <option value="#getallschools.sch_code#">#school#</option>
                </cfloop>
              </select></td>
            
              <td>6:</td>
              <td><select name="school_6" id="school_6">
                <option value="#getdata.school_6#" selected="selected">#getschools.school_6#</option>
                <cfloop query="getallschools">
                  <option value="#getallschools.sch_code#">#school#</option>
                </cfloop>
              </select></td>
              


Appreciate ya!



User is offlineProfile CardPM
+Quote Post


cfdvlpr

RE: Lists - Less Looping For A Little Faster Performance?

23 May, 2009 - 09:36 AM
Post #2

New D.I.C Head
*

Joined: 9 May, 2007
Posts: 5


My Contributions
So, if the data is read only, there's no need to hit the database everytime. One way to do it is output the data to a file in json format. Then, read that file and store it in a coldfusion variable.
User is offlineProfile CardPM
+Quote Post

armyCoder

RE: Lists - Less Looping For A Little Faster Performance?

26 May, 2009 - 05:43 AM
Post #3

D.I.C Head
**

Joined: 2 Feb, 2009
Posts: 54



Thanked: 1 times
My Contributions
QUOTE(cfdvlpr @ 23 May, 2009 - 10:36 AM) *

So, if the data is read only, there's no need to hit the database everytime. One way to do it is output the data to a file in json format. Then, read that file and store it in a coldfusion variable.


thanks for your reply. I'm trying to do some research on JSON but am in need of a quick lesson. I think the following line I wrote stores the query results into a JSON array:

CODE

<cfset allSchools = SerializeJSON(getallschools)>


But I can't figure out how to loop through the record set and get it to output to my list.

Here's a quick preview of the cfdump:

CODE
{"COLUMNS":["SCH_CODE","SCHOOL"],"DATA":[[1,"ABILENE CHRISTIAN UNIVERSITY"],[2,"ADAMS STATE COLLEGE"]


Thanks!

This post has been edited by armyCoder: 26 May, 2009 - 05:45 AM
User is offlineProfile CardPM
+Quote Post

armyCoder

RE: Lists - Less Looping For A Little Faster Performance?

26 May, 2009 - 01:52 PM
Post #4

D.I.C Head
**

Joined: 2 Feb, 2009
Posts: 54



Thanked: 1 times
My Contributions
Ok, here's what I've done:

CODE

<cfset allSchools = SerializeJSON(getallschools)>
<cfset allschoolslist = deserializeJSON(allSchools)>
<cfset colList=ArrayToList(allschoolslist.COLUMNS)>
<cfset xsch_code=ListFind(colList, "SCH_CODE")>
<cfset xschool=ListFind(colList, "SCHOOL")>


Then to loop in the list:

CODE

<cfloop index="i" from="1" to="#arraylen(allschoolslist.DATA)#">
                  <option value="#allschoolslist.DATA[i][xsch_code]#">#allschoolslist.DATA[i][xschool]#</option>
                </cfloop>


The page loads much faster, but these lists are in a spry tabbed panel, and clicking the tab still lags (about 2 seconds).

Any thoughts?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 02:21PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month