0

Here is the code:

IF(selected_item_id IS NOT NULL AND selected_category IS NOT NULL) THEN

    IF(selected_item_id <> "all") THEN

        SELECT i.id, i.name, i.summary, i.description, i.location, c.name AS 'category_name' FROM items i, categories c WHERE i.category_id = c.id AND i.id LIKE selected_item_id;

    ELSE IF(selected_item_id = "all" AND selected_category <> "all" AND selected_category in (SELECT name FROM categories)) THEN

        SELECT i.id, i.name, i.summary, i.description, i.location, c.name AS 'category_name' FROM items i, categories c WHERE i.category_id = c.id AND c.name LIKE selected_category;

    ELSE IF(selected_item_id = "all" AND selected_category = "all") THEN

        SELECT i.id, i.name, i.summary, i.description, i.location, c.name AS 'category_name' FROM items i, categories c WHERE i.category_id = c.id;

    END IF

END IF

When I try to save it, I get :

MySQL Said: #1064 near 'END IF' at line 17 (that's the last END IF)

Help is much appreciated.

1 Answer 1

1

You dont need to add space in between ELSE and IF. See this for details. And end you END IF with semicolon.

Sign up to request clarification or add additional context in comments.

1 Comment

OK. Now it works. I'll put this to be answer as soon as it allows it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.