comparing two strings

Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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.*.*.*...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

  6. #5

    Default 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

  7. #6

    Default Re: comparing two strings

    Originally posted by: mxstu
    > <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>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

  8. #7

    Default Re: comparing two strings

    ..
    trojnfn Guest

  9. #8

    Default 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

  10. #9

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139