I'm working on a tag system where an array (of tags) is queried and all rows with the same tags in the Tag column are selected.
The issue is that I used the IN condition which is a type of an OR function, which selected all the rows with the same tags as opposed to narrowing them down, for example.
Instead of narrowing down an image with tags like 'sun' and 'landscape' it would select all images with those tags.
What I'm looking for is an AND version of IN () or a substitute that can work with arrays.
This is just an example. In reality, the user can add as many tags as they want
+----+---------+---------+
| ID | ImageID | Tag |
+----+---------+---------+
| 1 | 2 | sun |
+----+---------+---------+
| 2 | 12 |landscape|
+----+---------+---------+
| 3 | 15 | field |
+----+---------+---------+
| 4 | 15 |landscape|
+----+---------+---------+
My code
$tag = $_POST['tag'];
$tag = preg_split("#/#", $tag);
$tag = implode("', '", $tag);
$query = "SELECT * FROM ComicStripTags WHERE `Tag` IN ('$tag')";
$result = mysqli_query($link, $query);
while ($row = mysqli_fetch_array($result)){
$ID[] = $row['ImageID'];
}
Thanks
P.S. I'm not working in SQL, im working in PHP