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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare

Status
Not open for further replies.

danarashad

Programmer
Nov 2, 2006
115
0
0
US
I need some help comparing data. What I am doing is looping through a table, and getting values. What I want to do is compare the values I receive against each other. Is this possible using coldfusion.

<cfquery name="statuscheck" datasource="#datasource#">
SELECT access.userid, access.buildingID, Questions.rec_id, Questions.UserId, Questions.status
FROM access INNER JOIN Questions ON access.sectionid = Questions.rec_id
where access.userid=#maintUserID# and questions.userid=#ID# and Questions.status=1;
</cfquery>

<cfif statuscheck.recordcount GT 1>
<cfoutput>#statuscheck.recordcount#</cfoutput>
<cfloop query="statuscheck">
<cfoutput>#buildingID# </cfoutput>
</cfloop>
</cfif>
It outputs the values, but what i want to do is compare the output, to one another.
 
What values do you want to compare? access.buildingID to Questions.rec_id? access.sectionid = Questions.rec_id?

See if this works
Code:
<cfquery name="statuscheck" datasource="#datasource#">
	SELECT access.userid, access.buildingID, Questions.rec_id, Questions.UserId, Questions.status
	FROM access INNER JOIN Questions ON access.sectionid = Questions.rec_id
	where access.userid=#maintUserID# and questions.userid=#ID# and Questions.status=1;
</cfquery>
    
<cfif statuscheck.recordcount GT 1>
	<cfoutput>#statuscheck.recordcount#</cfoutput>
	<cfloop query="statuscheck">
		<cfoutput>#buildingID#</cfoutput>
		
		<cfset comparison = Compare(statuscheck.buildingID, statuscheck.rec_id)>
		<cfswitch expression = #comparison#>
			<cfcase value = "0">
				#statuscheck.buildingID# equals #statuscheck.rec_id#
			</cfcase>
		</cfswitch>
	</cfloop>
</cfif>

The above code is untested.

For more info:
____________________________________
Just Imagine.
 
When you say you want to "compare the values I receive against each other" do you mean submitted from a form against what you hold in the database?

Comparisions are easy to do, you can use the following:

<cfif a EQ b>
<cfif NOT CompareNoCase(a, b)> - used for text comparisions
<cfif NOT Compare(a, b)> - used for numerical comparisions

what is the code that you have at the moment?

Tony

 
Ok, this is what I want to do, the statuscheck loop outputs the values 37,38,39. I want to know if there's away to compare those values to one each other. Example 37 gets compared to 38, then 39. Then 38 gets compared to 37, and 39. Or i guess is there away to see if value appears more than once. Say if i run the query for a different user and get the values 37,37,40,50 is there away for me to output 37 appears more than once. That would really be a big help
Thanks for all your help, sorry about any confusion
 
Sounds to me like you need to have a look at the list value count function.


you can turn the generated output of the query into a list by using the ValueList() function, and then loop over the query and using the list value count see how many times the val appears in the list. something like this:

Code:
....your query

<cfset myList = Valuelist(statusCheck.buildingID)>

<cfloop query="statusCheck">
  <cfset numTimes = ListValueCount(variables.mylist, statusCheck.buildingID)>
  <cfif numTimes>
    Exists in the list <cfoutput>#variables.numTimes#</cfoutput>
  </cfif>
</cfloop>

Hope this helps!

Tony
 
Would it be easier to just change up your query and let it give you a count of how many 37's are returned?


Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Yes thats what I want to do. Is check against those. Thanks for your help on this one guys/gals.
By the way its he, not she.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top