For some reason things aren't working, here is the code I am using, for some reason the results are really weird. I am wondering about the <cfset user = id of person> why is currentfriendlist and total friend list set to this as well. What I am seeing happen is the "i" is equaling the user id of the person. Our table is set up as such,
Id Userid Friendid
1 1 2
2 2 1
3 3 2
4 2 3
5 10 1
6 1 10
If I set the lookingfor to 10, as it is in this instance, and user to 3 I get 10 was found at 1,
If I switch those, 3 looking for, 10 user then I get "Not in your network"
Neither of which are correct,
Please Help
<!--- Create a query that contains every person in your database --->
<cfquery name="everyone" datasource="Dizzot">
SELECT Id,UserId,FriendId
FROM Friends.Friendslist
</cfquery>
<!--- This function will return a comma-delimited list of the ID numbers of people who are friends with #currentUser# --->
<cffunction name="getFriends" access="private" output="false" returntype="string">
<!--- The id of the user whose friends we're searching for --->
<cfargument name="currentUser" type="numeric" required="yes" />
<!--- All of the friends who have been found so far --->
<cfargument name="currentFriends" type="string" required="yes" />
<cfquery name="friends" dbtype="query">
SELECT UserId
FROM everyone
WHERE FriendId = <cfqueryparam value="#currentUser#" CFSQLType="CF_SQL_INTEGER"
/>
<!--- Exclude everyone who has already been found as a friend --->
<cfloop index="i" list="#currentFriends#">
AND UserID <> <cfqueryparam value="#i#" CFSQLType="CF_SQL_INTEGER"
/>
</cfloop>
</cfquery>
<!--- Return a comma-delimited list of the ID numbers of the friends found for this person --->
<cfreturn ValueList(friends.UserID) />
</cffunction>
<cfset lookingfor = "10" />
<cfset user = "3" />
<cfset currentfriendlist = user />
<cfset totalfriendList = user />
<cfset found = false />
<!--- Make sure we only do this 6 times --->
<cfloop index="i" from="1" to="6">
<!--- Perform once for every friend at this level --->
<cfloop index="j" list="#currentfriendlist#"
>
<cfset nextlevelfriendlist = "" />
<!--- Get the friends of this person, excluding any friends who were previously found --->
<cfset friends = getFriends(j,totalfriendli
st) />
<!--- If the person we are looking for is in this list, notify the user and break out --->
<cfif ListFind(friends,lookingfo
r) GT 0>
<cfset found = true />
<cfoutput>#lookingfor# was found at level #i#</cfoutput><cfbreak />
<!--- If we still haven't found the person --->
<cfelse>
<!--- add all the friends that were found on this level to be checked on the iteration --->
<cfset nextlevelfriendlist = ListAppend(nextlevelfriend
list,frien
ds) />
<!--- add all the friends that were found on this level to be excluded from future checks --->
<cfset totalfriendlist = ListAppend(totalfriendlist
,friends) />
</cfif>
</cfloop>
<!--- Set the list of friends found on this level to be searched the next time around --->
<cfset currentfriendlist = nextlevelfriendlist />
</cfloop>
<cfif ListFind(friends,lookingfo
r) EQ 0>
Not in your Network
</cfif>