title: How do you replace id numbers with names since the columns aren't joined directly?  (PHP/MySQL)
body: <p>Let's say you have a database with two tables named "clients" and "referrals".</p>
  
  <p>TABLE clients has two columns: "id" and "name".<br>
  TABLE referrals also has two columns: "id" and "referred_by"</p>
  
  <p>Both "id" columns are <code>PRIMARY_KEY</code>, <code>AUTO_INCREMENT</code>, <code>NOT_NULL</code></p>
  
  <p>TABLE clients has three rows:</p>
  
  <pre><code>1 | Jack  
  2 | Frank  
  3 | Hank  
  </code></pre>
  
  <p>TABLE referrals also has three rows:</p>
  
  <pre><code>1 | 0  
  2 | 1  
  3 | 2  
  </code></pre>
  
  <p>Meaning, Jack is client 1 and was referred by no one; Frank is client 2 and was referred by Jack; Hank is client 3 referred by Frank.</p>
  
  <p>The SELECT command I used to display the meaning above was:</p>
  
  <pre><code>mysql_query("SELECT clients.id, clients.name, referrals.referred_by FROM clients INNER JOIN referrals ON clients.id=referrals.id");
  
  while ($row = mysql_fetch_array($result))
  {
      echo $row['id'] . " " . $row['name'] . " " . $row['referred_by'] . "&lt;br&gt;";
  }
  </code></pre>
  
  <p>Which outputs:</p>
  
  <pre><code>1 Jack 0  
  2 Frank 1  
  3 Hank 2  
  </code></pre>
  
  <p><strong>Now the real question is:</strong></p>
  
  <p>How should I modify the code so that it outputs the name of the referrer instead of their id?</p>
  
  <p>Meaning, it should look like this:</p>
  
  <pre><code>1 Jack  
  2 Frank Jack  
  3 Hank Frank
  </code></pre>
  
  <p>Thanks in advance ~</p>
  
  <p>Edit: Make sure to mention how I should update the array as I'm lost on how I should update that whole echo line.</p>