I have two tables; one table with users, a second table contains the categories.
On the site's frontend are a bunch of filters to filter users. One of the filters is a dropdown with checkboxes that have category values. E.g: admin, user, publisher etc can be selected.
When multiple checkboxes have been checked get a random user from users but only random user that has all selected categories.
The users have an unique id. The categories have an unique id, the category value (admin, publisher, user etc) and the user-id so it can be tied together I think.
Important note:
($value
= the posted value from checkbox, also keep in mind that the categories.category = $value
part is added dynamically depending on the amount of selections, I append that using a foreach)
My current query:
$sql = "SELECT users.*, categories.*
FROM users
INNER JOIN categories
ON users.id = categories.user_id
WHERE categories.category = '$value' AND
categories.category = '$value'
--> continues endlessly depending on the amount of selections that have been made.
ORDER BY RAND()
LIMIT 0,1";
For some reason this only works when one checkbox is selected. When a second one, or more a selected, it breaks, no errors, it just simply doesn't find any result.
I hope my question is clear, if you need any future information, please let me know!