School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,156 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,985 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? Rate Topic: -----

#1 armyCoder  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 56
  • Joined: 02-February 09


Dream Kudos: 0

Posted 21 May 2009 - 01:20 PM

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.

<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!
Was This Post Helpful? 0
  • +
  • -


#2 cfdvlpr  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 5
  • Joined: 09-May 07


Dream Kudos: 0

Posted 23 May 2009 - 09: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.
Was This Post Helpful? 0
  • +
  • -

#3 armyCoder  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 56
  • Joined: 02-February 09


Dream Kudos: 0

Posted 26 May 2009 - 05:43 AM

View Postcfdvlpr, on 23 May, 2009 - 10:36 AM, said:

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:

<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:

{"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

Was This Post Helpful? 0
  • +
  • -

#4 armyCoder  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 56
  • Joined: 02-February 09


Dream Kudos: 0

Posted 26 May 2009 - 01:52 PM

Ok, here's what I've done:

<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:

<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?
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



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