Question

I'm using FQL to receive data from Facebook. More specific: Data from public events from fan pages.

Right now my query only takes the events that have a start time before or equal to now. So if the time is 15:01 and the start_time is 15:00, then the event is not on the list. That's where I need help. What you need to know is that not all events have an end_time. So I either have to do an if-statement or a case in there where clause.

My original code:

SELECT
        name, pic, start_time, end_time, location, description, eid, host
    FROM
        event
    WHERE
        eid IN ( SELECT eid FROM event_member
        WHERE uid = 1
        OR uid = 2 )
    AND
        start_time >= now()
    ORDER BY
        start_time desc

I have tried to put in the following code instead of start_time >= now() but the code haven't worked.

            CASE
            WHEN end_time IS NULL then 'start_time >= now()'
            ELSE 'end_time >= now()'

Thank you for your help.

Was it helpful?

Solution 2

I found out that neither if-statement nor case statements are allowed in FQL.

I found a list of available functions, operators etc. at http://steve.veerman.ca/2012/facebook-api-fql-tutorial/

My solution was to delete the following from the query:

    AND
    start_time >= now()

I also added now() to the select statement, to get the current time (despite that I could do that in PHP).

I would then get all the all events out, despite how relevant they were. I would them sort them with a if-statements and compare the start_time and the end_time, if it had a end_time.

OTHER TIPS

FQL does not allow for if-statements; however, I propose a better solution to your problem is to ignore end_time completely and select events based on a start_time range. For example, this will give events happening either 7 days before or 7 days after now:

SELECT
    name, pic, start_time, end_time, location, description, eid, host
FROM
    event
WHERE
    eid IN (
        SELECT eid FROM event_member
        WHERE uid = 1 OR uid = 2 
    )
    AND
    (
        start_time >= (now() - (60*60*24*7)) AND
        start_time <= (now() + (60*60*24*7))
    )
ORDER BY
    start_time desc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top