D
D
Dmitry2017-04-13 11:01:40
MySQL
Dmitry, 2017-04-13 11:01:40

Search for tickets, how to make a condition?

Good afternoon.
You need to organize a search for tickets for air flights. Created several test flights in the database with departure dates 04/16/2017 and return 04/29/2017, on the Moscow-Stockholm route (four tickets in total).
If you are looking for a round trip ticket:
The date of departure and date of return are set. Display tickets in pairs, back and forth. If there is no ticket for one of the dates, then output nothing.
If you are looking for a one-way ticket:
It's simple, show the ticket for the date of departure.
In the search model, I made the following search conditions:

$query->andWhere([
            'status' => Flights::STATUS_ACTIVE,
            'date_start' => [strtotime($this->date_from . ' 00:00'), strtotime($this->date_to . ' 00:00')],
            'city_start_id' => [$this->city_from, $this->city_to]
        ]);

What I expect:
If you select the dates 04/16/2017 and 04/29/2017 and select the cities Moscow-Stockholm, get all tickets for these dates.
What I get:
If I select the specified dates and cities, then in the end I have four tickets as a result.
If I change the date of return or departure to any other, and there are no tickets for this date in the database, then I get two tickets either there or back. And it is necessary that nothing is displayed, just a message that no tickets were found for the specified dates.
The same situation is with the cities of departure and return. If I select a city for which there are no tickets, then I get either a ticket there or a ticket back for the specified dates, but I need nothing to be displayed, only a message that no tickets were found.
How do I correctly compose the search condition?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-04-13
@slo_nik

As I understand it, you need to do 2 samples and union

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question