• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

A Little Coldfusion help?

Participant ,
Nov 18, 2008 Nov 18, 2008

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

436

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 18, 2008 Nov 18, 2008
I am so big fool, how i forgot this small little function

Thanks GUys Cheeers

Votes

Translate

Translate
Explorer ,
Nov 18, 2008 Nov 18, 2008

Copy link to clipboard

Copied

What are you looking for the like clause to be?
e.g. LIKE 'B' or LIKE 'BAG'

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 18, 2008 Nov 18, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 18, 2008 Nov 18, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 18, 2008 Nov 18, 2008

Copy link to clipboard

Copied

LATEST
I am so big fool, how i forgot this small little function

Thanks GUys Cheeers

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation