PHP Query MySQL Tables from IDs from other tables
<p>I have a database with several tables. I'm able to query IDs from a single table. What I'd like to do is Use those IDs to query another tables IDs, then use these new IDs to query fields from the final table. Here is what I am currently doing:</p>

<p>Here is how I acquire the first set of IDs:</p>

<pre><code>$returnedPost = mysqli_query($con, "SELECT Region_ID FROM Region WHERE RegionName='" . $queryVar . "'");

function resultToArray($result) {
    $rows = array();
    while ($row = $result-&gt;fetch_assoc()) {
        $rows[] = $row;
   }
    return $rows;
}
$rows = resultToArray($returnedPost);
//$rows[x]['Region_ID'];//returns Region_ID 1...n
</code></pre>

<p>I'd like to use the IDs in <code>$rows</code> to be able to query a new set of IDs from other tables as follows:</p>

<pre><code>$newTbl = mysqli_query($con, "SELECT Location_ID FROM Location WHERE Region_ID=" . $rows[$x]['Region_ID']);
$rows2 = resultToArray($newTbl);
$finalTbl = mysqli_query($con, "SELECT Field1, Field2 FROM Posts WHERE Location_ID=" . $rows2[$x]['Location_ID']);
</code></pre>

<p>Can someone please tell me how I can accomplish this? Thanks.</p>