SELECT * FROM table_1 WHERE id = id in table_2
<p>Been working on this for a while; Need to select data from a table where the ID column matches the ID from another table. </p>

<p>My code so far:</p>

<pre><code>&lt;?php
$sql = "SELECT * FROM input";
$sql2 = "SELECT * FROM output WHERE question_id =".$row["id"];
$result = $conn-&gt;query($sql);
$result2 = $conn-&gt;query($sql2);

if ($result-&gt;num_rows &gt; 0) {
  $index = 0;
  while($row = $result-&gt;fetch_assoc()) {
    $index++;
    ?&gt;

    &lt;?php
    echo '&lt;input type="hidden" name="questionid" value="'. $row['id'].'"/&gt;';
    ?&gt;

    &lt;?php

    if ($result2-&gt;num_rows &gt; 0) {
      while($row2 = $result2-&gt;fetch_assoc()) {
      }
    } else {
      echo "0 results";
    }
  }
} else {
  echo "0 results";
}
$conn-&gt;close();
?&gt;
</code></pre>

<p>I know I m missing something important here. Any suggestions are appreciated.</p>