L
L
lexstile2020-05-18 00:08:10
SQL
lexstile, 2020-05-18 00:08:10

How to create a condition for filtering?

Table:
5ec1a59553f9b785291337.png
UI:
5ec1a5e457df4441435873.png
Condition:

Array
(
    [day_1] => 1
    [month_1] => 1
    [year_1] => -1000
    [day_2] => 10
    [month_2] => 2
    [year_2] => -12
)

    SELECT events.id, events.name as event_name, events.date_start, events.date_end, events.country_id, events.description, events.day_1, events.day_2, events.month_1, events.month_2, events.year_1, events.year_2, countries.name as country_name, countries.cluster, links.links, images.images FROM events
    LEFT JOIN countries ON events.country_id = countries.id
    LEFT JOIN (SELECT event_id, GROUP_CONCAT(link) as links FROM links GROUP BY event_id) AS links ON events.id = links.event_id
    LEFT JOIN (SELECT event_id, GROUP_CONCAT(name) as images FROM images GROUP BY event_id) AS images ON events.id = images.event_id
    WHERE (events.year_1 >= :year_1 && (events.month_1 >= :month_1 || events.month_1 IS NULL) && (events.day_1 >= :day_1 || events.day_1 IS NULL)) AND (events.year_1 <= :year_2 && (events.month_2 <= :month_2 OR events.month_2 IS NULL) && (events.day_2 <= :day_2 OR events.day_2 IS NULL)) 
    ORDER BY events.year_1, events.month_1, events.day_1 asc
    LIMIT 30

It is not possible to compose a condition in such a way that unfilled fields (NULL) participate in the selection and are normally sorted - asc, desc.
Plus, the first element on the UI is not sorted - asc, desc.
The fields are filled according to the mask: dd.mm.yyyy || dd.mm.-yyyy
Can only be specified as the lower or upper date limit.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question