fabrizio
fabrizio

Reputation: 259

Facebook fql search by first letter of the name

Hello guys i'm trying to do a fql query that search the friends by first letter of the name, i did this query but doesn't show me the right result.

In this case i tried to get all my friends with the first letter "g" but CONTAINS doens't do what i'm looking for. There is another way?

SELECT uid , first_name, last_name FROM user WHERE uid IN 
(SELECT uid2 FROM friend WHERE uid1 = me()) AND ( CONTAINS('g')
AND  strpos(lower(name),lower('g')) >=0 ) ORDER BY first_name ASC

Upvotes: 0

Views: 641

Answers (1)

Rahil Arora
Rahil Arora

Reputation: 3674

The problem is with your usage of strpos(). You query will retrieve all your friends having a letter 'g' in their name. And, I think there's no point of using a contains() here.

This query will work fine for your task:

SELECT uid , first_name, last_name FROM user WHERE uid IN 
(SELECT uid2 FROM friend WHERE uid1 = me()) AND 
strpos(lower(first_name),lower('g')) = 0 ORDER BY first_name ASC

As you can see here, I'm using strpos(lower(first_name),lower('g')) = 0. This will retrieve only those friends having 'g' as the first letter in their first name.

Upvotes: 1

Related Questions