Home > Enterprise >  How to I search the MySQL Database with multiple PHP Arrays and output the results?
How to I search the MySQL Database with multiple PHP Arrays and output the results?

Time:04-15

Okay. I don't know if this question has already been answered, but from what I searched up, it hasn't...?

So, my question is, how do I search the MySQL Database with multiple PHP Keywords?

Let's assume that this is my Database structure

Anime
- Name [Example: Autumn Sanctuary]
- Season_ID [1 = Fall 2020, 2 = Summer 2021, 3 = Winter 2022, 4 = Fall 2023]
- Director_ID [1 = Mark, 4 = Zuckler, 5 = Julius]

And I have three different Anime:

Anime 1: [Very cool Anime name], [2], [5]
Anime 2: [Fruits Watery Basket], [1], [4]
Anime 3: [Another One], [4], [1]

Now, this is my query:

Season_ID: 2; Director_ID: 5;

This is simple, yes. But now, what if I search for multiple seasons or directors?

Season_ID: Array[1,2]; Director_ID: Array[4,5]

What is the PHP/MySQL Query I need to execute?

I am currently really at a loss there, since I don't seem to find any answers on that. I only found similar questions but those work with executing multiple queries, but I want to execute it with one single query.

Does anyone know the solution? If you need further details, let me know!

Best regards-

CodePudding user response:

Speaking only of MySQL you could do something like

SELECT * FROM Anime WHERE Session_ID IN (1,2);

You can also add AND|OR clauses

SELECT * FROM Anime WHERE Session_ID IN (1,2) AND Director_ID IN (4,5);
SELECT * FROM Anime WHERE Session_ID IN (1,2) OR Director_ID IN (4,5);
  • Related