title: PHP / MySQL relation between 2 tables
body: <p>I am using the following tables:</p>
  
  <ol>
  <li>artists</li>
  <li>related_artists</li>
  </ol>
  
  <p>The idea is when I enter an artist's page with an artist_id I can use that id to load related artists. The following code works, but how do I put it in a single query? I can't figure it out.</p>
  
  <p>To connect related_artists with artists I created the following code:</p>
  
  <pre><code>$sql = "SELECT related_artist_id FROM related_artists WHERE artist_id = 1";
  $res = mysqli_query($db, $sql);             
  if (!$res) {
      echo "Er is een fout opgetreden."; 
      exit;
  } else {
      while ($row = mysqli_fetch_array($res)) {
      $query = 'SELECT * FROM artists WHERE  artist_id = '.$row["related_artist_id"];
      print_r($query."&lt;br /&gt;\n");
      $result = mysqli_query($db, $query);
      if ($result) {
          while ($test = mysqli_fetch_array($result)) {
          echo $test["lastName"]."&lt;br /&gt;\n";
          }
      } else { 
          echo "It doesn't work";
          exit;
      }       
    }
  } 
  </code></pre>