Selecting by details with MySQL, after join : <p>First I'll introduce what I'm trying to achieve and how I'm doing it.</p>

<p>I have three tables, <code>Posts</code>, <code>Details</code>, and <code>Posts_Details</code>.</p>

<p><code>Posts</code> is the table where I keep the basic post data, <code>Details</code> is keeping the detail instances, with information about the title of the detail, possible values and some information if the detail is required for input, display flags etc. <code>Posts_Details</code> is the entity that represents the <code>M-&gt;N</code> relation which keeps one value of the detail, so it has three attributes, the id pairs of the post and detail and a value.</p>

<p>What I'm trying to setup is, a search functionality.</p>

<p>The first part of the search is simple, I use <code>Posts.title LIKE '%?%'</code> and the client is happy with the way it functions, I know its limitations, but this is really basic search functionality for now. The next feature is what brings me the troubles, as I don't feel like I know how to form the relation properly and I'm already behind the schedule to stop working and read up on relations.</p>

<p>I need to create a feature like "advanced search" where the user could not only pick the category and title keyword, but also match the details with drop-down inputs. I'm working with PHP and PDO, but I don't think that's too much relevant here as my problem is more SQL-related.</p>

<p>How I tried to solve this - I'm parsing the get data and collecting it in an associative array with details id as keys and the values as value, so I thought to iterate over the array and append the rules in the WHERE part of the SQL string. I kind of get some result with this approach after I parse the mashed columns, but it doesn't feel right, I feel like I'm doing just a hack-around.</p>

<p>Is there a "righter" way to implement this kind of search by details where I'll make a rule for selecting posts with values from the list of details after the three tables are joined?</p>
