4 Replies Latest reply on Nov 18, 2008 6:06 PM by thenotorious_flag

    A Little Coldfusion help?

    thenotorious_flag
      I a looking into somthing that can match my String value.

      I have a title in my database as:

      BLONDE AND GIRL

      What i am trying to do extract the first character of BLONDE AND GIRL as B

      So I can match my url value with B and extract the records which match this value:

      I am using an query like:

      SELECT jokes.*, categories.*
      FROM
      jokes
      INNER JOIN categories ON jokes.catID = categories.catID
      WHERE
      <cfif IsDefined('arguments.title') AND arguments.title NEQ "">
      title LIKE #getNameInitials(arguments.title)#

      I am using getNameInitials cflib function but it is not working:

      getNameInitials has this code:

      function getNameInitials(str) {
      var newstr = "";
      var word = "";
      var i = 1;
      var strlen = listlen(str," ");
      for(i=1;i lte strlen;i=i+1) {
      word = ListGetAt(str,i," ");
      newstr = newstr & UCase(Left(word,1));
      }
      return newstr;
      }

      Plz Guide Me

      Thanks
        • 1. Re: A Little Coldfusion help?
          scottcook Level 1
          What are you looking for the like clause to be?
          e.g. LIKE 'B' or LIKE 'BAG'
          • 2. Re: A Little Coldfusion help?
            Level 7
            nightwolf666 wrote:
            > I a looking into something that can match my String value.

            So many issues in one little post.

            Lets start with the getNameInitials() function. It apparently returns a
            simple string of the first letters of all the words of the string passed
            into it. Using your example it is going to return 'BAG'.

            I'm not sure why you need all of that. If you just want the first
            letter of the sting, 'BLONDE AND GIRL' it would be simply be
            left('BLONDE AND GIRL',1).

            Secondly your LIKE statement is missing quotes and percents it should
            read something as LIKE 'left(arguments.title,1)%' or however you want to
            pattern match the database field.

            Finally, if arguments.title is undefined or an empty string then you
            will have a hanging where clause. Your SQL will be rendered as:

            SELECT jokes.*, categories.*
            FROM
            jokes
            INNER JOIN categories ON jokes.catID = categories.catID
            WHERE

            And this will throw an error by any database I have ever used.
            • 3. Re: A Little Coldfusion help?
              Level 7
              Ian Skinner wrote:
              > Secondly your LIKE statement is missing quotes and percents it should
              > read something as LIKE 'left(arguments.title,1)%' or however you want to
              > pattern match the database field.
              >

              CORRECTION:
              LIKE '#left(arguments.title)#%'

              I forgot the pound signs in my first post.

              P.S.
              Of course the standard recommendation to learn and use <cfqueryparam...>
              in your SQL stands.
              • 4. Re: A Little Coldfusion help?
                thenotorious_flag Level 1
                I am so big fool, how i forgot this small little function

                Thanks GUys Cheeers