Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with lists and loops 1

Status
Not open for further replies.

jgroove

Programmer
Jul 9, 2001
43
US
I am trying to find strings inside lists of other stings. What I have is two tables the first is Sessions with a column LocationID which is a comma delimited list of UUID's the second table is Location with the primary key LocationID. I am trying to create a new table from the old so that instead of Sessions.LocationID being a list of locations that it will have a record for each one, but at the same time if a session isn't being held at a certain locatain that a record will be created with a flag set to false. Here is the code that I have so far :
Code:
<!---query for locations of a certain group (will eventually loop over all groups) --->

<cfquery name=&quot;qLocation&quot;>
	select LocationID from Locations where GroupID='1'
</cfquery>

<!--- convert query to list --->
<cfparam name=&quot;listLocation&quot; default=&quot;&quot;>
<cfloop query=&quot;qLocation&quot;>
     <cfset listLocation=listappend(listLocation,qLocation.LocationID)>
</cfloop>
<cfset qualifiedlistLocation=listqualify(listLocation,&quot;'&quot;)>


<!--- query all sessions --->
<cfquery name=&quot;qSessions&quot;>
	select LocationID from Sessions
</cfquery>


<!--- loop over all sessions and find locations that are in session records  ---->
<cfloop query=&quot;qSessions&quot;>
	<cfloop index=&quot;locID&quot; list=&quot;#qSessions.LocationID#&quot; delimiters=&quot;,&quot;>
		<cfif ListFind(qualifiedlistLocation,qSessions.LocationID,&quot;,&quot;)>
			true  
<!--- create record and set location flag to true --->
		<cfelse>
			false
<!--- create record and set locatin flag to false --->
		</cfif>
	</cfloop><br>
</cfloop>


right now I know that it is looping correctly through everythings because I get the correct number of lines, but everything comes out false. Does any of this make sense?
 
I think it's in your <CFIF> statement:

[tt]<!---query for locations of a certain group (will eventually loop over all groups) --->[/tt]
[tt]<cfquery name=&quot;qLocation&quot;>[tt]
select LocationID from Locations where GroupID='1'
[tt]</cfquery>[tt]

[tt]<!--- convert query to list --->[/tt]
[tt]<cfparam name=&quot;listLocation&quot; default=&quot;&quot;>[tt]
[tt]<cfloop query=&quot;qLocation&quot;>[tt]
[tt]<cfset listLocation=listappend(listLocation,qLocation.LocationID)>[tt]
[tt]</cfloop>[tt]
[tt]<cfset qualifiedlistLocation=listqualify(listLocation,&quot;'&quot;)>[tt]


[tt]<!--- query all sessions --->[/tt]
[tt]<cfquery name=&quot;qSessions&quot;>[tt]
select LocationID from Sessions
[tt]</cfquery>[tt]


[tt]<!--- loop over all sessions and find locations that are in session records ---->[/tt]
[tt]<cfloop query=&quot;qSessions&quot;>[tt]
[tt]<cfloop index=&quot;locID&quot; list=&quot;#qSessions.LocationID#&quot;>[tt]
[tt]<!--- <cfif ListFind(qualifiedlistLocation,qSessions.LocationID,&quot;,&quot;)> --->[/tt]
[tt]<cfif ListFind(qualifiedlistLocation, locID)>[tt]
true
[tt]<!--- create record and set location flag to true --->[/tt]
[tt]<cfelse>[tt]
false
[tt]<!--- create record and set locatin flag to false --->[/tt]
[tt]</cfif>[tt]
[tt]</cfloop>[tt][COLOR=000080]<br>[/color]
[tt]</cfloop>[tt]


BTW, if you are running I beleive ColdFusion 4.5 or higher, you could use the QuotedValueList() function to make things a little easier.

[tt]<!---query for locations of a certain group (will eventually loop over all groups) --->[/tt]
[tt]<cfquery name=&quot;qLocation&quot;>[tt]
select LocationID from Locations where GroupID='1'
[tt]</cfquery>[tt]

[tt]<!--- convert query to list --->[/tt]
[tt]<cfset listLocation=QuotedValueList(qLocation.LocationID)>[tt]

[tt]<!--- query all sessions --->[/tt]
[tt]<cfquery name=&quot;qSessions&quot;>[tt]
select LocationID from Sessions
[tt]</cfquery>[tt]


[tt]<!--- loop over all sessions and find locations that are in session records ---->[/tt]
[tt]<cfloop query=&quot;qSessions&quot;>[tt]
[tt]<cfloop index=&quot;locID&quot; list=&quot;#qSessions.LocationID#&quot;>[tt]
[tt]<cfif ListFind(qualifiedlistLocation, locID)>[tt]
true
[tt]<!--- create record and set location flag to true --->[/tt]
[tt]<cfelse>[tt]
false
[tt]<!--- create record and set locatin flag to false --->[/tt]
[tt]</cfif>[tt]
[tt]</cfloop>[tt][COLOR=000080]<br>[/color]
[tt]</cfloop>[tt] - tleish
 
tleish,

thanks that was my problem exactly and thanks for pointing out the other function. It makes it much easier turning my queries into lists.

jgroove
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top