Say I have the array: $myArray = ["hello", "and"];
and then I have a table like:
| id | text |
|---|---|
| 1 | "hello larry!" |
| 2 | "hello bob, and how are you?" |
| 3 | "and what are you up to?" |
How can I run a query like
$stmt = $conn->prepare("SELECT text FROM myTable WHERE text CONTAINS allItemsIn(a) LIMIT 10");
$stmt->bind_param("a", $myArray);
$stmt->execute();
Ideally, I'd like the query to only return the row with id 2, as the text contains both the strings "hello" and "and". I don't want the order of the items in the array to matter, so even if the array had "hello" and "and" the other way around, it should still return row 2. How can I do this?
I thought about making a for loop, and for each item in $myArray, run a query where the text contains the item in the given index of $myArray, however, I realize that this could become quite slow, especially if $myArray contained a large amount of items.
Some posts asking for a similar thing's answers use WHERE x IN. I cannot use this, as text will never be in any item in $myArray, as text could be longer than some of the items in $myArray.