Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
Mattastic #1
comparing two strings
Hi,
I'm trying to query a table to tell if a username exists within it, but I
can't seem to compare the two strings and get it to work.
Any help would be great, heres my code
<cfset session.admin_user = "Lee Fletcher">
<cfset logfirstname = left(session.admin_user,find(" ", session.admin_user))>
<cfset logsurname = right(session.admin_user,find(" ",
reverse(session.admin_user)))>
<cfquery datasource="#dsn_cis#" username="#dsn_username#"
password="#dsn_password#" name="tutors">
SELECT tgfull_desc FROM StudentsWithCourses WHERE TGstage_code = 'ENRL' OR
TGstage_code
= 'TRIN' AND acad_period = '05/06';
</cfquery>
<cfoutput query="tutors">
<cfset string = trim(tgfull_desc)>
<cfset tutorgroup = left(string,find(" ", string) - 1)>
<cfset surname = mid(string, len(tutorgroup) + 1, len(string) - find(",",
reverse(string)) - len(tutorgroup))>
<cfset seniortutor = right(string,find(" ", string) - 1)>
<cfset firstname = mid(string,find(",", string) + 1, len(string) -
(find(",", string) + 1) - 5)>
<cfset username = logfirstname & " " & logsurname>
<cfset tutorname = firstname & " " & surname>
<cfif username is tutorname>
You are a tutor
</cfif>
</cfoutput>
Mattastic Guest
-
comparing Dates
Hi all, I'm building a sort of calendersystem with the ability for users to make reservations for meetingrooms. All reservations are stored in... -
Extracting strings delimited by other strings
Hi, I need to write some code that will allowed embedded, specially formatted comments to document test cases within a program (SAS code). The... -
comparing array value...
Hello there, could somebody let me know how do i compare the contents of an array that I have... To be specific. my array contains something... -
Comparing values
i have created three fields named (username, surname & pin) and when the user enters in the information, i want it to compare the values from three... -
IP and hostname comparing
Anyone who can help me with a IP thingie? I want to compare a IP adress with a IP "String" with wildcards (*) like 127.0.0.1 equals to 127.*.*.*... -
Dan Bracuk #2
Re: comparing two strings
So you want to do this?
"I'm trying to query a table to tell if a username exists within it"
Do you know the user name? If so, why are you trying to compare strings, why
not simply add that criteria to the where clause of your query?
Dan Bracuk Guest
-
BKBK #3
Re: comparing two strings
It might be due to all that logic in the cfsets. Show us one tgfull_desc
data item, to help us retrace. It's also good practice to first ensure your
result
set is not empty.
<cifi tutors.recordcount GT 0>
<cfoutput query="tutors">
....
</cfoutput>
</cfif>
BKBK Guest
-
maashu #4
Re: comparing two strings
Not to nit-pick, but I'll usually substitute
<cfif tutors.recordcount GT 0>
for
<cfif tutors.recordcount>
...
I'm not sure if one way is better than the other, but all things equal it's a
little less typing.
Cheers,
-m
maashu Guest
-
mxstu #5
Re: comparing two strings
> <cfif tutors.recordcount GT 0>
Well, the way I see it is that "recordCount" represents a number, not a
boolean value (even if the other cfif statement does work). Therefore, my
preference would be for the "GT 0" syntax. I also think it is more clear than
treating the number as a boolean value.
< /end $0.02>
mxstu Guest
-
LeadFoot #6
Re: comparing two strings
Originally posted by: mxstu
Well, the way I see it is that "recordCount" represents a number, not a> <cfif tutors.recordcount GT 0>
boolean value (even if the other cfif statement does work). Therefore, my
preference would be for the "GT 0" syntax. I also think it is more clear than
treating the number as a boolean value.
< /end $0.02>True, your logic holds water, but before a numeric value can be
assigned to the recordcount of a query, it must first exist. The boolean
represents the existance of the query result. Besides, IIRC, it's fractionally
faster.
LeadFoot Guest
-
-
mxstu #8
Re: comparing two strings
Originally posted by: LeadFoot
True, your logic holds water, but before a numeric value can be assigned to
the recordcount of a query, it must first exist. The boolean represents the
existance of the query result. Besides, IIRC, it's fractionally faster.
It could very well be fractionally faster, but since it doesn't involve a
measurable performance gain, I usually opt for clarity. Like I said though,
that is just my preference.
mxstu Guest
-
PaulKD #9
Re: comparing two strings
Mattastic,
I'm not going to attempt to work out how to compare your strings, but a
solution to your problem is, if you are the owner, is to redo your database.
You should not be parsing the fields - they should have their own fields in the
database with tutor group being joined to a tutors table, ditto for names...
they should be joined with an id to a personnel table.
btw - I think you have a logic error in your WHERE clause... is it
WHERE (TGstage_code = 'ENRL' OR TGstage_code = 'TRIN') AND acad_period =
'05/06';
or
WHERE TGstage_code = 'ENRL' OR (TGstage_code = 'TRIN' AND acad_period =
'05/06');
My guess is the former.
PaulKD Guest



Reply With Quote

